Esempio n. 1
0
     $response["error"] = true;
     $response["message"] = "Your file is too large. The maximum size is 10 MB";
     echoResponse(400, $response);
 } else {
     // Allow certain file formats
     if ($file_type != "jpg" && $file_type != "png" && $file_type != "jpeg" && $file_type != "gif") {
         $response["error"] = true;
         $response["message"] = "Only JPG, JPEG, PNG & GIF files are allowed";
         echoResponse(400, $response);
     } else {
         if (move_uploaded_file($_FILES["photo"]["tmp_name"], $target_file)) {
             $response = array();
             // reading post params
             $place_id = $app->request->post('place_id');
             $db = new db_handler();
             $result = $db->addPhoto($place_id, $file_id . "." . $file_type);
             if (!$result) {
                 $response["error"] = true;
                 $response["message"] = "There was an error uploading your file";
                 echoResponse(400, $response);
             } else {
                 $response["error"] = false;
                 $response["message"] = "Photo added successfully";
                 $response["file"] = $file_id . "." . $file_type;
                 echoResponse(200, $response);
             }
         } else {
             $response["error"] = true;
             $response["message"] = "There was an error uploading your file";
             echoResponse(400, $response);
         }