diff options
author | Simon Rettberg | 2016-04-29 20:55:59 +0200 |
---|---|---|
committer | Simon Rettberg | 2016-04-29 20:55:59 +0200 |
commit | cbd23b7d191327a7cfb6a98e657659045da71af3 (patch) | |
tree | f029ab85c3ac07d3f2a56b4359fd36c265898d6d /apis/webservice/upload.php | |
parent | More Progress; Merged changes from ufpr up to 775cdbd29f5d0f70946d1d5ff09c091... (diff) | |
download | slx-admin-cbd23b7d191327a7cfb6a98e657659045da71af3.tar.gz slx-admin-cbd23b7d191327a7cfb6a98e657659045da71af3.tar.xz slx-admin-cbd23b7d191327a7cfb6a98e657659045da71af3.zip |
Second half of merge....
Diffstat (limited to 'apis/webservice/upload.php')
-rw-r--r-- | apis/webservice/upload.php | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/apis/webservice/upload.php b/apis/webservice/upload.php new file mode 100644 index 00000000..50ada40e --- /dev/null +++ b/apis/webservice/upload.php @@ -0,0 +1,62 @@ +<?php +if(!isset($_POST['uploadid'])){ + echo json_encode(array( + "errormsg"=>"Not logged in", + "status" => "error", + "msg" => "")); + die(); +}elseif (!isset($_FILES['fileToUpload'])){ + echo json_encode(array( + "errormsg"=>"No file received", + "status" => "error", + "msg" => "")); + die(); +} + +$upload = Database::queryFirst("Select * from upload where token = :token", + array( "token" => $_POST['uploadid'])); +if($upload['userid']!= $_SESSION['userid']){ + echo json_encode(array( + "errormsg"=>"Not same owner", + "status" => "error", + "msg" => "")); + die(); +} + +$name = $_FILES["fileToUpload"]["name"]; +$upload['nremaining'] = $upload['nremaining'] - 1; +if ($upload['nremaining'] < 0){ + echo json_encode(array( + "errormsg"=>"Already received all the parts", + "status" => "error", + "msg" => "")); + die(); +} +$target_file = $target_dir.$_POST['uploadid']."/".$name; +if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)){ + $ret = Database::exec("UPDATE upload SET nremaining= :nremaining". + " WHERE id=:id", array( + "id"=>$upload['id'], + "nremaining"=>$upload['nremaining'] + )); + if ($upload['nremaining'] == 0) { + echo json_encode(array( + "errormsg"=>"", + "status" => "ok", + "msg" => "Upload successful, sending to taskmanager")); + //passa pro taskmanager; + die(); + }else{ + echo json_encode(array( + "errormsg"=>"", + "status" => "ok", + "msg" => "Upload successful, waiting next part")); + die(); + } +} else { + echo json_encode(array( + "errormsg"=>"", + "status" => "error", + "msg" => "Error on upload, please resend")); +} + |