diff --git a/data.json b/data.json new file mode 100644 index 0000000..cb99cc9 --- /dev/null +++ b/data.json @@ -0,0 +1 @@ +{"data":{"filename":"angadi-catalog-008.zip","checklist_item_id":2,"date_uploaded":"2021-06-25 11:14:36","filesize":4096,"checksum":"da39a3ee5e6b4b0d3255bfef95601890afd80709"}} \ No newline at end of file diff --git a/fileUploadScript.php b/fileUploadScript.php new file mode 100644 index 0000000..42424c3 --- /dev/null +++ b/fileUploadScript.php @@ -0,0 +1,95 @@ + 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..."; + + +?> diff --git a/index.html b/index.html new file mode 100644 index 0000000..2fcdf46 --- /dev/null +++ b/index.html @@ -0,0 +1,14 @@ + + +
+ +