How do Upload File using PHP
In PHP we are using two file which used upload file in the server.First one Html file and another one is PHP file .
In the Html file we are going get file content and PHP file we are process it and Upload into Particular file path.
Coding
In the coding section we are show First html file.In the html file we are going to get file and sent to php file using POST method.Here code for HTML file.
Upload.html:
1)In the form enctype/form data encding when submitting to the server.
<html> <body> <form enctype="multipart/formdata" action="saveupload.php" method="post"> <input type="file" name="fileToUpload"> <input type="submit" value="UploadFile"> </form> </body> </html> |
saveupload.php:
1)$_FILES["file"]["name"] it is used get the name of file
1)$_FILES["file"]["name"] it is used get the name of file
2)$_FILES["file"]["type"] it is used to get type of file
3)$_FILES["file"]["size"] it is used to get size of file
4)$_FILES["file"]["tmp_name"] it is give tmp name of file which is ued to store the file in folder.
<?php echo "<table border=\"1\">"; echo "<tr><td>Client Filename: </td> <td>" . $_FILES["file"]["name"] . "</td></tr>"; echo "<tr><td>File Type: </td> <td>" . $_FILES["file"]["type"] . "</td></tr>"; echo "<tr><td>File Size: </td> <td>" . ($_FILES["file"]["size"] / 1024) . " Kb</td></tr>"; echo "<tr><td>Name of Temp File: </td> <td>" . $_FILES["file"]["tmp_name"] . "</td></tr>"; echo "</table>"; move_uploaded_file($_FILES["file"]["tmp_name"], "C:/upload/" . $_FILES["file"]["name"]); ?> |
move_uploaded_file(dest_file,source_file)
Here Upload is folder we can create in you local computer it is save the file.
0 comments:
Post a Comment