Uploading files via PHP is a simple process just you need to mention the uploading file enctype=”multipart/form-data” in form tag. If you missed enctype there will be an error no index file.
Let’s see an example how to upload files using PHP.
upload.html
<form action="upload.php" enctype="multipart/form-data" method="post">
<input name="t1" type="file" />
<input type="submit" value="upload file" />
</form>
input type=”file” which gives a text box with browse button to upload files.
upload.php
<?php
$tmpname =$_FILES['t1']['tmp_name'];
$filename =$_FILES['t1']['name'];
$filetype =$_FILES['t1']['type'];
$filesize =$_FILES['t1']['size'];
echo "Temporary File Name : $tmpname <br>";
echo "File Name : $filename <br>";
echo "File Type : $filetype <br>";
echo "File Size : $filesize <br>";
move_uploaded_file($tmpname,$filename);
?>
The above coding gets the file enctype and file name,size,type and temporary file path and prints at last move_uploaded_file() which moves temporary file to a destination. Note: (You can set path for moving file to particular location eg: move_uploaded_file($tmpname,”D:/upload/”.$filename); )