For file upload, we need to use the typefile type and enctype attribute of the form in HTML. This is what we all need. Of course, we must use the FILE function library, string function library, directory function library, and $ _ FILES [] in the PHP function library. Each website may have many restrictions on file upload. These restrictions include the type = file type of the form in HTML and the enctype attribute of the file upload. This is what we all need. Of course, we must use the FILE function library, string function library, directory function library, and $ _ FILES [] in the PHP function library.
Each website may have many restrictions on the upload of files. These restrictions include the file type, file size, extension, the existence of the upload directory, and the existence of the uploaded file, directory writability and readability, renaming uploaded files, and copying files from the cache to the desired directory.
Of course, error preprocessing cannot be ignored! If we further discuss it, we can use the event log record for file operations.
We can use a program to implement these functions:
The first is our preset variable value, which includes the file size, file extension type, MIMI type, and whether to delete the switch variable.
$ DELETABLE = true;
Next, set the browser access variables and directory access variables:
$ Site_name = $ _ SERVER ['http _ host'];
$ Url_dir = http: //. $ _ SERVER ['http _ host']. dirname ($ _ SERVER ['php _ SELF ']);
$ Url_this = http: //. $ _ SERVER ['http _ host']. $ _ SERVER ['php _ SELF '];
$ Upload_dir = files /;
$ Upload_url = $ url_dir./files /;
$ Message =;
Create an upload directory and change the permission accordingly:
If (! Is_dir (files )){
If (! Mkdir ($ upload_dir ))
Die (upload_files directory doesn' t exist and creation failed );
If (! Chmod ($ upload_dir, 0755 ))
Die (change permission to 755 failed .);
}
Processing of user requests:
If ($ _ REQUEST [del] & $ DELETABLE ){
$ Resource = fopen(log.txt, );
Fwrite ($ resource, date (Ymd h: I: s). DELETE-$ _ SERVER [REMOTE_ADDR]. $ _ REQUEST [del] \ n );
Fclose ($ resource );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.