4000000) { $errors[] = "File exceeds maximum size (4MB)"; } if (empty($errors)) { $didUpload = move_uploaded_file($fileTmpName, $uploadPath); if ($didUpload) { echo "The file " . basename($fileName) . " has been uploaded"; } else { echo "An error occurred. Please contact the administrator."; } } else { foreach ($errors as $error) { echo $error . "These are the errors" . "\n"; } } } $data = array( 'filename' => $_FILES["the_file"]["name"], 'checklist_item_id' => 2, // temporary checklist_item_id 'date_uploaded' => date('Y-m-d h:i:s'), 'filesize' => filesize($currentDirectory['the_file']['temp_name']), 'checksum' => sha1_file($currentDirectory['the_file']['temp_name']), ); move_uploaded_file($_FILES["the_file"]["tmp_name"], $output_dir.$fileName); $ret[]= $fileName; echo "
"; echo json_encode($data['filename']); echo "
"; echo json_encode($data['checksum']); echo "
"; echo json_encode($data['filesize']); echo "
"; echo json_encode($data['date_uploaded']); // Read JSON file $json = file_get_contents('./data.json'); // encode array to json $jsone = json_encode(array('data' => $data)); //Decode JSON $json_data = json_decode($json,true); //Decode JSONe $jsone_data = json_decode($jsone,true); print_r($json_data); print_r($jsone_data); $jsa =serialize($json_data); $jsb =serialize($jsone_data); if($jsa["0"]["name"] == $jsb["0"]["name"]){ array_replace($json_data,$jsone_data); $jsonDatap = json_encode($jsone_data); file_put_contents('./data.json', $jsonDatap); } else { array_push($jsone_data, $data); $jsonDataf = json_encode($jsone_data); file_put_contents('./data.json', $jsonDataf); } //write json to file //if (file_put_contents("data.json", $jsone)) // echo "\r\n JSON file created successfully..."; //else // echo "\r\n Oops! Error creating json file..."; ?>