TYPE = "Submit"> td> tr>
TABLE>
Body>
Html>
Note that the ENCTYPE = "Multipart / Form-Data" section in the table. This must not be wrong, otherwise the server will not know what you are on.
send file.
Design uploader
Now we have completed the front part, let us carefully consider how the background is how to receive the file and save it to our designated
Record it. Let's start with PHP. This is the program of Submit.php3:
IF ($ myfile! = "None") {
Copy ($ MyFile, "/ Home / Berber / $ MyFile_Name");
Unlink ($ myfile);
}
Else {
Echo "You don't have any file";
}
?>
No matter what you believe, this is the entire process. What we do in the program is:
1. Check if a file has been uploaded to the server, passing if ($ myfile! = "None);
2. Copy files to the specified location.
3. Delete the temporary file.
When you press the submit button, the file will be uploaded from your computer to the temporary directory of the server. Files in the temporary directory
Named a temporary file. You should use the Name value of the file field to access it, here is $ myfile. Real file name Using File
The Name value of the field is plus "_name" to access it, here is $ myfile_name. Use the copy () function to copy the temporary file $ myfile
Bet to the specified directory, the copy file is named $ myfile_name. Don't forget to delete temporary files after completion, or you will have a lot of you.
Unwanted files.
Set file name
A thing that may make programmers can't sleep is to try to change the value of the value attribute of the File field. Not a lot of people know it
It is impossible. Although W3C said, it is actually, IE and Netscape are not allowed to set values for VAUE properties. It's a bit
Laugh, why can't I set an initial value so that users use it more convenient? If you do that, then you will find you
It comes to a safe vulnerability. You can imagine that you log in to my website, I can change the value of the File field in a table. So do you have to prevent me from uploading your / etc / passwd file? Further, I don't need you to press the submit button, I can set it first.
Set the value of the file field, then simulate the submission action through a javascript program ... Wow ... I can handle anything on your machine.
Document. For this reason, the browser is simply ignored by the value field of the File field in the tag.
Limit file size
Another cool feature is to limit the size option of the uploaded file. Just add a tag. You can:
This will not allow users to upload more than 100KB files.
Display file size
To display the file size, you can access the "_size" variable by the file field Name property value. In our example
That is to use $ myfile_size. So, if you want to tell the user to upload the size of the file, you can do it as follows:
Echo "You Have Just Uploaded $ MyFile_Name";
Echo "The size of the file is $ myfile_size";
Authority
Obviously you need to write permission on the target directory. If a user uses an inuts to upload files, then his username should be
Bobody. This user must have permissions written on the target directory. Otherwise, you may get an image below:
Warning: unable to create '/Home/berber/berber.txt':
Permission denied
In /Home/berber/Submit.php3 on line 5
转载请注明原文地址:https://www.9cbs.com/read-1281.html
|