You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

95 lines
2.7 KiB

<?php
$currentDirectory = getcwd();
$uploadDirectory = "/uploads/";
$errors = []; // Store errors here
$fileExtensionsAllowed = ['zip']; // These will be the only file extensions allowed
$fileName = $_FILES['the_file']['name'];
$fileSize = $_FILES['the_file']['size'];
$fileTmpName = $_FILES['the_file']['tmp_name'];
$fileType = $_FILES['the_file']['type'];
$fileExtension = strtolower(end(explode('.',$fileName)));
$uploadPath = $currentDirectory . $uploadDirectory . basename($fileName);
if (isset($_POST['submit'])) {
if (! in_array($fileExtension,$fileExtensionsAllowed)) {
$errors[] = "This file extension is not allowed. Please upload a . zip file";
}
if ($fileSize > 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 "</br>";
echo json_encode($data['filename']);
echo "</br>";
echo json_encode($data['checksum']);
echo "</br>";
echo json_encode($data['filesize']);
echo "</br>";
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...";
?>