It would be nice if you could upload files from a form. Here a complete example how to upload a file in php.
Now start the work…..
1st you have to create a HTML form for uploading file.
The HTML form is following:
<html>
<body>
<table border=”1″ align=”center”>
<tr><td>
<form action=”upload_file.php” method=”post”
enctype=”multipart/form-data”>
<label for=”file”>Filename:</label>
<input type=”file” name=”file” id=”file” />
<input type=”submit” name=”submit” value=”Upload” />
</tr></td>
</form>
</body>
</html>
Then save it as file_upload.html.
Now create the file uploading script,
<?php
if ($_FILES["file"]["error"] > 0)
{
echo “Error: ” . $_FILES["file"]["error"] . “<br />”;
}
else
{
echo “Upload: ” . $_FILES["file"]["name"] . “<br />”;
echo “Type: ” . $_FILES["file"]["type"] . “<br />”;
echo “Size: ” . ($_FILES["file"]["size"] / 1024) . ” Kb<br />”;
echo “Stored in: ” . $_FILES["file"]["tmp_name"];
}
?>
save this as file_upload.php. Run this program.
By using the global PHP $_FILES array you can upload files from a client computer to the remote server.
This the very simple way to uploading file.








3 comments
Comments feed for this article
July 10, 2008 at 6:13 am
Nandakumar
its very easy to understand ,,,,
October 21, 2008 at 7:32 am
Naseer Ahmad
ya Nandakumar is right…
plz give us little complex version. like limited size, limited file types etc…
March 17, 2009 at 9:12 pm
grasshopper
Naseer, way to be productive before being condescending.