$_FILES['uploadedFile']['name'], 'checklist_item_id' => 2, // temporary checklist_item_id 'date_uploaded' => time($_FILES['uploadedFile']['tmp_name']), 'filesize' => $_FILES['uploadedFile']['size'], 'checksum' => sha1_file($_FILES['uploadedFile']['tmp_name']), ); // sanitize file-name $newFileName = $fileName; //$checksum = md5(time() . $fileName) . '.' . $fileExtension // check if file has one of the following extensions $allowedfileExtensions = array('zip'); if (in_array($fileExtension, $allowedfileExtensions)) { // directory in which the uploaded file will be moved $uploadFileDir = './uploaded_files/'; $dest_path = $uploadFileDir . $newFileName; if(move_uploaded_file($fileTmpPath, $dest_path)) { $message ='File is successfully uploaded.'; } else { $message = 'There was some error moving the file to upload directory. Please make sure the upload directory is writable by web server.'; } } else { $message = 'Upload failed. Allowed file types: ' . implode(',', $allowedfileExtensions); } } else { $message = 'There is some error in the file upload. Please check the following error.
'; $message .= 'Error:' . $_FILES['uploadedFile']['error']; } } // 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["data"]["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_append('./data.json', $jsonDataf); } $_SESSION['message'] = $message; header("Location: index.php");