Implementation of file upload
Friends who are familiar with ASP may know that uploading files using ASP is not easy. PHP is different and it is easier to see the example: and as follows:
<!--File -->
<form ENCTYPE="multipart/form-data" ACTION="" METHOD=post>
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000">
Send this file: <INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Send File">
</form>
The following code receives the uploaded file
<?php
#document
if (rename($userfile,"\dir\)") {
echo "Success!";
}
else {
echo "Upload failed!";
}
?>
illustrate:
1. The temporary directory used in the file to indicate the placement of the file uploaded by PHP
2. If the uploaded file stored in a temporary directory is not moved or renamed, it will be deleted immediately.
3. The directory where the file is uploaded must have write permissions.
The final suggestion: Don’t let users upload files that can be executed, or they set them to be unexecutable. Everyone should know why.
Friends who are familiar with ASP may know that uploading files using ASP is not easy. PHP is different and it is easier to see the example: and as follows:
<!--File -->
<form ENCTYPE="multipart/form-data" ACTION="" METHOD=post>
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000">
Send this file: <INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Send File">
</form>
The following code receives the uploaded file
<?php
#document
if (rename($userfile,"\dir\)") {
echo "Success!";
}
else {
echo "Upload failed!";
}
?>
illustrate:
1. The temporary directory used in the file to indicate the placement of the file uploaded by PHP
2. If the uploaded file stored in a temporary directory is not moved or renamed, it will be deleted immediately.
3. The directory where the file is uploaded must have write permissions.
The final suggestion: Don’t let users upload files that can be executed, or they set them to be unexecutable. Everyone should know why.