PHP File Upload
In php you can upload file to server. To upload a file to the server, you need to create a form to specify which file you want to upload.
<form action="upload.php" method="post" enctype="multipart/form-data">
Filename: <input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
- The action attribute points to a .php file. This is the file that will process the uploaded file.
- There is an attribute called enctype, and its value is multipart/form-data.
- One of the input fields has type="file".
<?php
if ($_FILES["file"]["error"] == 0) {
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temporary filename: " . $_FILES["file"]["tmp_name"];
}
else {
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
?>


