Advertisement
metalx1000

Upload file with cURL to Website php

Jul 26th, 2016
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. <?php
  2. //curl -X POST -F "file=@/tmp/tux.png" "http://localhost/upload.php"
  3.  
  4. $valid_file = true;
  5. //if they DID upload a file...
  6. if($_FILES['file']['name'])
  7. {
  8.   //if no errors...
  9.   if(!$_FILES['file']['error'])
  10.   {
  11.     //now is the time to modify the future file name and validate the file
  12.     //$new_file_name = strtolower($_FILES['file']['tmp_name']); //rename file
  13.     if($_FILES['file']['size'] > (1024000)) //can't be larger than 1 MB
  14.     {
  15.       $valid_file = false;
  16.       $message = 'Oops!  Your file\'s size is to large.';
  17.     }
  18.    
  19.     //if the file has passed the test
  20.     if($valid_file)
  21.     {
  22.       $name = basename($_FILES['file']['name']);
  23.       //move it to where we want it to be
  24.       //move_uploaded_file($_FILES['file']['tmp_name'], './uploads/'.basename($new_file_name));
  25.       move_uploaded_file($_FILES['file']['tmp_name'], './uploads/'.$name);
  26.       $message = 'Congratulations!  Your file was accepted.';
  27.     }
  28.   }
  29.   //if there is an error...
  30.   else
  31.   {
  32.     //set that to be the returned message
  33.     $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['file']['error'];
  34.   }
  35. }
  36.  
  37. echo $message;
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement