Mining PHP file Upload principles. We all know that PHP has powerful functions, which brings me a lot of convenience. let's take a look at the implementation of the PHP file Upload type. PHP supports file upload, but not all support. we all know that PHP has powerful functions, which brings me a lot of convenience. let's take a look at the implementation of the PHP file Upload type. PHP supports file upload, but not all websites that support PHP support this function, especially free websites.
To upload an object, you must first add the <FORM> Table of the object to be uploaded in HTML.
- <FormMethod=Post Action="Upload. php" ENCTYPE="Multipart/form-data">
- <InputType="File" Name="Upload_file">
- <InputType="Submit" Name="Submit" Value="Upload files">
When using PHP to upload a file type, you need to perform a detailed check on the content, such as whether to allow reading and writing files, the file format, and whether the file size is within your specified size.
- <?
- $File_size_max=1000000;
- // Limit the maximum file upload capacity (bytes)
- $Store_dir="/Public/www/upload /";
- // Storage location of uploaded files
- $Accept_overwrite=True;
- // Allow reading and writing files
- // Check the file size
- If ($ upload_file_size> $ file_size_max ){
- Echo "Sorry, your file capacity exceeds the limit ";
- Exit;
- }
- // Check the read/write file
- If (file_exists ($ store_dir. $ upload_file_name )&&&&! $ Accept_overwrite ){
- Echo "the file already exists and cannot be copied ";
- Exit;
- }
- // Copy the file to the specified directory
- If (! @ Copy ($ upload_file, $ store_dir. $ upload_file_name )){
- Echo "failed to copy the file ";
- Exit;
- }
- Echo "file uploaded ";
- ?>
It should be noted that during PHP file upload, the file is copied to the temporary directory (temp) on the server, and then the "copy () "function to copy files from the temporary directory to the storage directory you specified. Because the program uses a temporary directory for work, if the server blocks the above functions for security reasons, you cannot use the PHP Upload function. In addition, you also need to set the file mode to 777 (CHMOD 777) for the uploaded file directory, otherwise PHP will not have the permission to read and write the file.
Bytes. PHP supports file upload, but not all support...