kisukedeath

File upload

Sep 15th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. //if they DID upload a file...
  2. if($_FILES['photo']['name'])
  3. {
  4.     if (($_FILES["photo"]["type"] == "image/gif")
  5.     || ($_FILES["photo"]["type"] == "image/jpeg")
  6.     || ($_FILES["photo"]["type"] == "image/png")
  7.     || ($_FILES["photo"]["type"] == "image/pjpeg"))
  8.     {
  9.     //if no errors...
  10.     if(!$_FILES['photo']['error'])
  11.     {
  12.         //now is the time to modify the future file name and validate the file
  13.         $new_file_name = strtolower($_FILES['photo']['tmp_name']); //rename file
  14.         if($_FILES['photo']['size'] > (512000)) //can't be larger than (512kb) / 1 MB 10240000
  15.         {
  16.             $valid_file = false;
  17.             $ruta = '';
  18.             $message = 'Oops!  Your file\'s size is to large.';
  19.         }else{
  20.             $valid_file = true;
  21.         }
  22.        
  23.         //if the file has passed the test
  24.         if($valid_file == true)
  25.         {
  26.  
  27.             //move it to where we want it to be
  28.             //move_uploaded_file($_FILES['photo']['tmp_name'], $path.$_FILES['photo']['name']);
  29.  
  30.             $currentdir = getcwd();
  31.             $target = $currentdir .'\\profiles\\' . basename($_FILES['photo']['name']);
  32.             move_uploaded_file($_FILES['photo']['tmp_name'], $target);
  33.  
  34.             $message = 'Congratulations!  Your file was accepted.';
  35.         }
  36.     }
  37.     //if there is an error...
  38.     else
  39.     {
  40.         //set that to be the returned message
  41.         $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['photo']['error'];
  42.     }
  43.     }else{
  44.         $message = 'Formato invalido';
  45.         $ruta = '';
  46.     }
  47. }
  48.  
  49.  
  50. echo $message."<br>";
  51. //you get the following information for each file:
  52. echo $_FILES['photo']['name']."<br>";
  53. echo $_FILES['photo']['size']."<br>";
  54. echo $_FILES['photo']['type']."<br>";
  55. echo $_FILES['photo']['tmp_name']."<br>";
Advertisement
Add Comment
Please, Sign In to add comment