Skip to content

Instantly share code, notes, and snippets.

@vincurekf
Last active March 10, 2017 14:07
Show Gist options
  • Save vincurekf/a266c2dba85e0d88ea69cc2613c93721 to your computer and use it in GitHub Desktop.
Save vincurekf/a266c2dba85e0d88ea69cc2613c93721 to your computer and use it in GitHub Desktop.
Upload test script
<?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