1. Create upload folder

2. Then create the upload.html ( file ) Form . And put following code, 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.

#####################################

php” method=”POST”> Please choose a file:

#####################################

This form sends data to the file “upload.php”, which is what we will be creating next to actually upload the file.

3. Then create the ” upload.php ” file , The actual file upload is very simple:

Place the following code

#####################################
<!–––?php $target = “upload/”; $target = $target . basename( $_FILES[‘uploaded’][‘name’]) ; $ok=1; 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.”; } ?>–>
#####################################

This very small piece of code, this will upload files sent to it by your HTML form.

This script will allow you to upload files from your browser to your hosting, using PHP.

TO LIMIT THE UPLOAD FILE SIZE

Add the following code to your “upload.php”

#####################################
if ($uploaded_size > 350000) { echo “Your file is too large.<br>”; $ok=0; }
#####################################

If the file is larger than 350k, they are given a file too large error, and we set $ok to equal 0.You can change this line to be a larger or smaller size if you wish by changing 350000 to a different number. Or if you don’t care about file size, just leave these lines out.

TO LIMIT UPLOAD FILES BY TYPE

Add the following code to your “upload.php”

#####################################
if ($uploaded_type ==”text/php”) { echo “No PHP files<br>”; $ok=0; }
#####################################

The code above checks to be sure the user is not uploading a PHP file to your site. If they do upload a PHP file, they are given an error, and $ok is set to 0.

#####################################
if (!($uploaded_type==”image/gif”)) { echo “You may only upload GIF files.<br>”; $ok=0; }
#####################################

In our second example we only allow users to upload .gif files, and all other types are given an error before setting $ok to 0. You can use these basic examples to allow or deny any specific file types.

To Sum IT UP

#####################################
<!–––?php $target = “upload/”; $target = $target . basename( $_FILES[‘uploaded’][‘name’]) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo “Your file is too large.–>
“; $ok=0; } //This is our limit file type condition if ($uploaded_type ==”text/php”) { echo “No PHP files
“; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo “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)) { echo “The file “. basename( $_FILES[‘uploadedfile’][‘name’]). ” has been uploaded”; } else { echo “Sorry, there was a problem uploading your file.”; } } ?>
#####################################