PHP File Upload

PHP is its ability to manage file uploads to your server. To allow users to upload a file to the server, you first need to provide a form for them to specify which file they want to upload. Once they click the submit button of the form, the action page is called. This is the page that needs to contain the PHP code to process the uploaded file.

Look at the following HTML form for uploading files:

<form action="upload_file.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>

* The enctype attribute of the <form> tag specifies which content-type to use when submitting the form. “multipart/form-data” is used when a form requires binary data, like the contents of a file, to be uploaded
* The type=”file” attribute of the <input> tag specifies that the input should be processed as a file. For example, when viewed in a browser, there will be a browse-button next to the input field

The “upload_file.php” file contains the code for uploading a file:

<?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"];
}
?>

And want to know how to save the uploaded file or image you may refer this link http://qualitypointtech.net/forum/viewtopic.php?f=25&t=257&start=0&hilit=upload

By using the global PHP $_FILES array you can upload files from a client computer to the remote server.

The first parameter is the form’s input name and the second index can be either “name”, “type”, “size”, “tmp_name” or “error”. Like this:

* $_FILES[“file”][“name”] – the name of the uploaded file
* $_FILES[“file”][“type”] – the type of the uploaded file
* $_FILES[“file”][“size”] – the size in bytes of the uploaded file
* $_FILES[“file”][“tmp_name”] – the name of the temporary copy of the file stored on the server
* $_FILES[“file”][“error”] – the error code resulting from the file upload

Posted in Php