A very strange question about downloading files in PHP

Source: Internet
Author: User
The following form submission page HTMLcode & lt; formaction = & quot; upload. php & quot; method = & quot; post & quot; enctype = & quot; multipart/form-data & quot; & gt; & lt; it is a strange problem to upload files in input PHP.
The following form submission page
HTML code
  

Upload. php page code
PHP code
  If ($ _ FILES ["spic"] ["error"]! = 0) {switch ($ _ FILES ["spic"] ["error"]) {case 1: echo "the file uploaded exceeds php. the value restricted by the upload_max_filesize option in 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" only part of the file is uploaded. "; Break; case 4: echo" no file is uploaded. "; Break; default: echo" Unknown error ";}} else {echo" no error ";}


I have a maximum size in the form MAX_FILE_SIZE = 1 M. If I upload a word image larger than 1 M, the system will prompt, but I can upload an exe larger than 1 M.
After viewing PHP. INI, it is even more depressing.

;;;;;;;;;;;;;;;;
; File Uploads;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
File_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; Specified ).
Upload_tmp_dir = "d:/wamp/tmp"

; Maximum allowed size for uploaded files.
Upload_max_filesize = 2 M

I have not modified the configuration file!
The maximum configuration file size is 2 MB. However, if I upload an exe file of about 30 MB, no error is reported.

What's the problem?

------ Solution --------------------
In case of a problem, first enable error_reporting (E_ALL) and then remedy the problem
------ Solution --------------------
How can it take effect if the values of hidden fields in your form are not judged?

Since you set the maximum upload size in php. ini. It should take effect. Check whether the server is restarted.
------ Solution --------------------
PHP code
If (isset ($ _ POST ['sub']) {} else {echo 'file is too large or other unknown errors! ';} // If it is less than 1 M, echo $ _ POST ['sub'] will display upload;, but if it is greater, echo $ _ POST ['sub'] will show null;
------ Solution --------------------
Yes. you should use the upstairs method to determine whether the sub form button is clicked and submitted to determine whether the file is uploaded.

However, when debugging, uploading a 1.73MB exe file can be uploaded normally. it is estimated that it is a configuration problem, not a code problem.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.