Friday, October 25, 2013

Very Simple File Upload Script on PHP

Very Simple File Upload Script on PHP


Note : This php script is base on php file uploading only there are not security features.

We need two files. 1st one is for generate form. It can name as "uploadform.html"

<html>
<body>
<form action="uploadfile.php" method="post"

enctype="multipart/form-data">

<label for="file">Filename:</label>

<input type="file" name="file" id="file"><br>

<input type="submit" name="submit" value="Submit">

</form>

</body>
</html> 

2nd one is for handle uploaded file on web sever save and ect...

It can name as "uploadfile.php"

<?php
$file_saving_path = "upload_directory/";

$file_saving_path = $file_saving_path . basename( $_FILES['file']['name']); 

if(move_uploaded_file($_FILES['file']['tmp_name'], $file_saving_path)) 
{
echo "The file ".  basename( $_FILES['file']['name']). " has been uploaded";
}
else
{
echo "There was an error uploading the file, please try again!";
} ?> 

0 comments:

Post a Comment