Uploading file Forms
<title> Upload a file form </title>
<body>
<form enctype= "Multipart/form-data" action= "" method= "POST" >
Please select File:<br>
<input name= "Upload_file" type= "file" ><br>
<input type= "Submit" value= "Upload file" >
</form>
</body>
<?
$upload _file=$_files[' upload_file ' [' tmp_name '];
$upload _file_name=$_files[' upload_file ' [' name '];
if ($upload _file) {
$file _size_max = 1000*1000;//1M limit file upload maximum capacity (bytes)
$store _dir = "d:/";//storage location of uploaded files
$accept _w = false;//allows overwriting of the same file
$upload _file_size=$_files[' upload_file ' [' Size '];
Check File size
if ($upload _file_size > $file _size_max) {
echo "Sorry, your file size is greater than the provision";
Exit
}
Check read and write files
if (file_exists ($store _dir. $upload _file_name) && $accept _w) {
Echo "file with the same file name exists";
Exit
}
Copy files to the specified directory
if (!move_uploaded_file ($upload _file, $store _dir. $upload _file_name)) {
echo "Failed to copy file";
Exit
}
}
Echo "<p> you uploaded the file:";
echo $_files[' upload_file ' [' name '];
echo "<br>";
The original name of the client machine file.
Echo "file has a MIME type of:";
echo $_files[' upload_file ' [' type '];
The MIME type of the file requires the browser to provide support for that information, such as "Image/gif".
echo "<br>";
Echo "Upload file size:";
echo $_files[' upload_file ' [' Size '];
The size of the uploaded file, in bytes.
echo "<br>";
Echo "file was temporarily stored as:" After uploading;
echo $_files[' upload_file ' [' tmp_name '];
Temporary file names stored on the server after the files have been uploaded.
echo "<br>";
$Erroe =$_files[' upload_file ' [' Error '];
Switch ($Erroe) {
Case 0:
Echo "Upload success"; Break
Case 1:
Echo "uploaded a file that exceeds the value of the Upload_max_filesize option limit in php.ini."; Break
Case 2:
Echo "The size of the uploaded file exceeds the value specified by the Max_file_size option in the HTML form. "; Break
Case 3:
Echo "file is only partially uploaded";
Case 4:
Echo "No files were uploaded";
}
?>