Htinkphp uploads an image and reports "illegal image files" solution

Source: Internet
Author: User
Htinkphp uploads an image and reports "illegal Image File". it is not available on the server, but the txt file is successfully uploaded, which is definitely not a problem with directory permissions. Solution // Save the attachment to the specified path $ upload & nbsp ;=& nbsp; new & nbsp; UploadFile (); // & nbsp; instantiated upload class $ upload-htinkphp uploads an image and reports "invalid image file"
Yes locally, but not on the server, but the txt file is successfully uploaded, which is definitely not a problem with directory permissions. Solution



// Save the attachment to the specified path
$ Upload = new UploadFile (); // instantiate the upload class
$ Upload-> maxSize = 2*1024*1024; // sets the attachment upload size.
$ Upload-> allowExts = explode (',', 'jpg, gif, png, jpeg, txt, doc, docx, wps, xls, et, zip, tar, rar, gz, 7z'); // sets the attachment Upload type.
$ Upload-> savePath = 'tpl/Public/Uploads/task_description/'; // Set the attachment upload Directory

// Modify the name of the uploaded file
$ File_name = $ _ FILES ['taskfile'] ['name'];
$ Expand_name = explode (".", $ file_name );
$ New_name = date ('ymdhis ', time ().'. '. strtolower ($ expand_name [count ($ expand_name)-1]);

$ _ FILES ["taskfile"] ["name"] = $ new_name;

If (! $ Upload-> upload () {// upload error message
Echo $ upload-> getErrorMsg ();
// $ This-> error ($ upload-> getErrorMsg ());
} Else {
$ Info = $ upload-> getUploadFileInfo ();
// Save the data to the database
$ Data ['wlfileurl'] = $ info [0] ['savepath']. $ new_name;
} Thinkphp? Image upload? Share:
------ Solution --------------------
Since the server can be used locally, it must have been a restriction on the server.
Try uploading a small image.
------ Solution --------------------
Try another few images. There may be image problems, and there may be dozens of utf8 files which are the best to check your php file encoding. encoding problems may also cause Upload failure.

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.