PHP image upload is a strange problem. please help me!

Source: Internet
Author: User
PHP image upload is a strange problem. please help me!
Echo "here"; // ------------------------------------------------------------- if (is_uploaded_file ($ this-> tmp_name) === false) {$ this-> alert ("Upload failed. ");}


The problem lies in the above, which always prompts that the upload fails.

$ This-> tmp_name:
D: \ ServerPHP \ fileuploadtmp \ php89BD. tmp

Die (var_dump ($ _ FILES); prints data as well

My front-end was uploaded using JQ:


Reply to discussion (solution)

You only gave two lines of code. who knows what you did before?

You only gave two lines of code. who knows what you did before?



Private function check_upload () {// if (empty ($ _ FILES) = false) when a file is uploaded) {// The original file name is the file name $ this-> imageData ['filename'] = $ _ FILES ['imgfile'] ['name']; // temporary file name on the server $ this-> tmp_name = $ _ FILES ['imgfile'] ['tmp _ name']; // File size $ this-> imageData ['filesize'] = $ _ FILES ['imgfile'] ['size']; // check the file name if (! $ This-> imageData ['filename']) {$ this-> alert ("Select a file. ") ;}// Check the directory if (@ is_dir ($ this-> save_path) ===false) {$ this-> alert (" the upload directory does not exist. ") ;}// Check the directory write permission if (@ is_writable ($ this-> save_path) ===false) {$ this-> alert (" the upload Directory has no write permission. ");} // Check whether the upload is complete. if (@ is_uploaded_file ($ this-> tmp_name) === false) {$ this-> alert (" Upload failed. ");} // Check the file size if ($ this-> imageData ['filesize']> $ this-> max_size) {$ this-> alert ("The size of the uploaded file exceeds the limit. ") ;}// Check the directory name $ this-> dir_name = empty ($ _ GET ['dir'])? 'Image': trim ($ _ GET ['dir']); if (empty ($ this-> ext_arr [$ this-> dir_name]) {$ this-> alert ("The directory name is incorrect. ");} If ($ this-> dir_name = 'image') {$ this-> imageData ['type'] = 'image ';} else {$ this-> imageData ['type'] = 'file';} $ this-> get_ext (); // Check the if extension (in_array ($ this-> file_ext, $ this-> ext_arr [$ this-> dir_name]) === false) {$ this-> alert ("the file upload extension is not allowed. \ N only supports ". implode (", ", $ this-> ext_arr [$ this-> dir_name])." format. ");}}}

Var_dump (is_file ($ this-> tmp_name ));

See why there are two \ paths \\

Var_dump (is_file ($ this-> tmp_name ));

See why there are two \ paths \\



D: \ ServerPHP \ fileuploadtmp \ php89BD. tmp
Is this path unable to be uploaded normally?

Var_dump (is_file ($ this-> tmp_name ));

See why there are two \ paths \\



Bool (true)
Is this a code file?

I asked you what else I did before is_upload_file.
You have pasted a method definition. how can you know that this method has been executed? What has been done after execution?


Public function upload () {error_reporting (E_ALL); ini_set ('display _ errors ', 1); $ filename = $ _ FILES ['imgfile'] ['name']; $ type = $ _ FILES ['imgfile'] ['type']; $ tmp_name = $ _ FILES ['imgfile'] ['tmp _ name']; $ size = $ _ FILES ['imgfile'] ['size']; $ error = $ _ FILES ['imgfile'] ['error']; $ kk = move_uploaded_file ($ tmp_name, PATH_DATA. "/upload /". $ filename); var_dump ($ kk); // false is returned here}

The upload path is correct after debugging, and temporary file printing is also available. Returns false at move_uploaded_file.

Bool move_uploaded_file (string filename, string destination)


This function checks and ensures that the file specified by filename is a valid file to be uploaded (that is, the file is uploaded through the http post Upload mechanism of PHP ). If the file is valid, move it to the file specified by destination.

If filename is not a valid file to be uploaded, no operation is performed. move_uploaded_file () returns FALSE.

If filename is valid but cannot be moved for some reason, no operation will occur. move_uploaded_file () returns FALSE. A warning is also issued.

$ Kk = move_uploaded_file ($ tmp_name, PATH_DATA. "/upload/". $ filename );

Print out $ tmp_name, PATH_DATA. "/upload/". $ filename.

Worship My God .....

Solved the problem. thank you ~~

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.