Last active
March 10, 2017 14:07
-
-
Save vincurekf/a266c2dba85e0d88ea69cc2613c93721 to your computer and use it in GitHub Desktop.
Upload test script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Velmi jednoduchý příklad zpracování fotek z aplikace | |
*/ | |
$uploads_path = "uploads/"; | |
// | |
$upload = $_POST["upload"]; | |
$op = $_POST["op"]; | |
$user_id = $_POST["user_id"]; | |
$category_id = $_POST["category_id"]; | |
$timestamp = $_POST["timestamp"]; | |
// | |
foreach ($_FILES as $file) { | |
$file_name = basename( $file['name']); | |
$file_tmp_name = $file['tmp_name']; | |
$file_path = $uploads_path . $file_name; | |
if( !move_uploaded_file($file_tmp_name,$file_path) ){ | |
// pokud se nahrání souboru nepovedlo, | |
// ukončit a vrátit error | |
echo json_encode(array( | |
"success" => false | |
,"error" => "Soubor "+$file_name+" se nepovedlo nahrát!" | |
)); | |
die; | |
}; | |
}; | |
// vrátit úspěšný výsledek v JSON formátu | |
echo json_encode( | |
array( | |
"success" => true | |
,"upload" => $upload | |
,"op" => $op | |
,"user_id" => $user_id | |
,"category_id" => $category_id | |
,"timestamp" => $timestamp | |
) | |
); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment