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.
85 lines
2.6 KiB
85 lines
2.6 KiB
<?php
|
|
session_start();
|
|
|
|
$message = '';
|
|
if (isset($_POST['uploadBtn']) && $_POST['uploadBtn'] == 'Upload')
|
|
{
|
|
if (isset($_FILES['uploadedFile']) && $_FILES['uploadedFile']['error'] === UPLOAD_ERR_OK)
|
|
{
|
|
// get details of the uploaded file
|
|
$fileTmpPath = $_FILES['uploadedFile']['tmp_name'];
|
|
$fileName = $_FILES['uploadedFile']['name'];
|
|
$fileSize = $_FILES['uploadedFile']['size'];
|
|
$fileType = $_FILES['uploadedFile']['type'];
|
|
$fileNameCmps = explode(".", $fileName);
|
|
$fileExtension = strtolower(end($fileNameCmps));
|
|
|
|
$data = array(
|
|
'filename' => $_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.<br>';
|
|
$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");
|