Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 KB | None | 0 0
  1.     $f3->route ('POST|GET /upload',
  2.     function() {
  3.  
  4.     // Reference. upload script from https://www.w3schools.com/php/php_file_upload.asp
  5.  
  6.         $target_dir = $_SERVER['DOCUMENT_ROOT'] ."/328/signup/images/";
  7.  
  8.         $imageFileName = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  9.        // echo "<BR>" .$imageFileName ." <br>";
  10.         $uploadOk = 1;
  11.         $imageFileType = pathinfo($imageFileName,PATHINFO_EXTENSION);
  12.         // Check if image file is a actual image or fake image
  13.         if(isset($_POST["submit"])) {
  14.             $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  15.             if($check !== false) {
  16.                 echo "File is an image - " . $check["mime"] . ".";
  17.                 $uploadOk = 1;
  18.             } else {
  19.                echo "File is not an image.";
  20.                 $uploadOk = 0;
  21.             }
  22.         }
  23.         // Check if file already exists
  24.         if (file_exists($imageFileName)) {
  25.             echo "Sorry, file already exists.";
  26.             $uploadOk = 0;
  27.         }
  28.         // Check file size
  29.         if ($_FILES["fileToUpload"]["size"] > 500000) {
  30.             echo "Sorry, your file is too large.";
  31.             $uploadOk = 0;
  32.         }
  33.         // Allow certain file formats
  34.         if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
  35.             && $imageFileType != "gif" ) {
  36.             echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  37.             $uploadOk = 0;
  38.         }
  39.         // Check if $uploadOk is set to 0 by an error
  40.         if ($uploadOk == 0) {
  41.             echo "Sorry, your file was not uploaded.";
  42.             // if everything is ok, try to upload file
  43.         } else {
  44.             // target_file
  45.             if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $imageFileName)) {
  46.           //      echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  47.             } else {
  48.         //        echo "Sorry, there was an error uploading your file.";
  49.             }
  50.         }
  51. //      $view = new View;
  52. //      echo $view->render('/pages/summery.php');
  53.         header('Location: /328/signup/summery');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement