I used thinkphp to write an image Upload background, but it was uploaded to the html code for display.-php Tutorial

Source: Internet
Author: User
I used thinkphp to write an image Upload background, but it was uploaded to the html code. I used thinkphp to write an image Upload background, but how was it displayed in the html code?
$ Upload = new \ Think \ Upload (); // instantiate the upload class $ upload-> maxSize = 3145728; // Set the attachment upload size $ upload-> exts = array ('jpg ', 'GIF', 'PNG', 'jpeg '); // Set the attachment upload type $ upload-> savePath = '1/'; // Set the attachment upload Directory // upload file $ info = $ upload-> upload (); if (! $ Info) {// upload error message $ this-> error ($ upload-> getError ());} else {// Upload successful $ this-> success ('upload successful! ', U ('index/index1 '));}


How to display the uploaded image ..


Reply to discussion (solution)

When the image storage path is uploaded successfully, a field in the database is recorded. This field is called when the page is displayed.

Since the upload is successful, it is estimated that the image path is incorrect. check whether the uploaded file path is correct.

Splicing path. path output is made based on the actual physical location during storage or output.
If there is a problem with the UPload class of the old version of tp, upgrade it to the latest version.

If (! $ Upload-> upload () {// upload error message $ this-> error ($ upload-> getErrorMsg ());} else {// obtain the information of the uploaded file after the upload is successful $ info = $ upload-> getUploadFileInfo ();} // Save the form data $ User = M ("User "); // instantiate the User object $ User-> create (); // create a data object $ User-> photo = $ info [0] ['savename']; // Save the uploaded photo and assemble $ User-> add () as needed; // write User data to the database $ this-> success ('Data Is saved successfully! ');}

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.