} break; default: throw new RuntimeException("Error Bad Extention"); break; } imagedestroy($rImg); imagedestroy($image_p); /* if ( !move_uploaded_file( $_FILES["upfile"]["tmp_name"], $location) ) { throw new RuntimeException('Failed to move uploaded file.'); } */ //add code to add to the db here // addPhoto($fileName, $user_id); if (isset($_SESSION['user_id'])) { $fileName .= '.' . $ext; $signupAddphoto = new Signup(); $current_user = $_SESSION['user_id']; $signupAddphoto->addPhoto($current_user, $fileName); $message = 'File is uploaded successfully. ' . $current_user . " " . $fileName; } } catch (RuntimeException $e) { $message = $e->getMessage(); $status = 500; $location = ''; } header("HTTP/1.1 " . $status . " " . $status_codes[$status]); $response = array("status" => $status, "status_message" => $status_codes[$status], "message" => $message, "location" => $location); echo json_encode($response); die;