Hide options

Basic fileupload example

Example how to script fileuploading using PHP
<?php
   if (isset($_FILES)){ 
      $target = "upload/"; 
      $target = $target . basename( $_FILES['uploaded']['name']) ;  

      if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){
         echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
      } 
      else {
         echo "Sorry, there was a problem uploading your file.";
      }
   }
?>

<form enctype="multipart/form-data" action="<?=$_SERVER['PHP_SELF'] ?>" method="POST">
   Please choose a file: <input name="uploaded" type="file" /><br />
   <input type="submit" value="Upload" />
</form>


Description

This is a minimal example how to deal with file uploads. Always limit the allowed filetypes, check the file size etc.

Use:

print_r($_FILES);

To see all variables and protect your server against malicious attacks


Top