Logo

Uploader using move_uploaded_file

Posted under » PHP on 25 October 2009

This script will allow you to upload files from your browser to your hosting, using PHP. The first thing we need to do is create an HTML form that allows people to choose the file they want to upload.

Please choose a file:

The upload.php file itself is very small.

<¿php
// make sure its writable
$target = "/unux/domains/public_html/docs/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

//This is our size condition
if ($uploaded_size > 350000)
 {
  $kontent .= "Your file is too large.
"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { $kontent .= "No PHP files
"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { $kontent .= "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { $kontent .= "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { $kontent .= "Sorry, there was a problem uploading your file."; } } ?>