index.html


  1. <html> 
  2.     <body> 
  3.         <form action="uploader.php" method="post" enctype="multipart/form-data"> 
  4.             <label for="file">Filename:</label> 
  5.             <input type="file" name="file" id="file" /><br /> 
  6.             <input type="submit" name="submit" value="Submit" /> 
  7.         </form> 
  8.     </body> 
  9. </html> 

 

uploader.php

 

  1. <?php 
  2. if($_FILES['userfile']['type'] != "p_w_picpath/gif") { 
  3.       echo "Sorry, we only allow uploading GIF p_w_picpaths"
  4.       exit
  5.  
  6. // Where the file is going to be placed  
  7. $target_path = 'uploaded_files/'
  8.   
  9. /* Add the original filename to our target path.   
  10. Result is "uploaded_files/filename.extension" */ 
  11. $target_path = $target_path . basename$_FILES['file']['name']);  
  12.  
  13. if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { 
  14.     echo "The file ".  basename$_FILES['file']['name']).  
  15.     " has been uploaded"
  16. else
  17.     echo "There was an error uploading the file, please try again!"
  18. ?>