I used thinkphp to write an upload image backstage but how to show it in the HTML code

Source: Internet
Author: User
I used thinkphp to write an upload image backstage but how to show it in the HTML code
           $upload = new \think\upload (); Instantiate upload class            $upload->maxsize = 3145728;//Set attachment upload size            $upload->exts = array (' jpg ', ' gif ', ' PNG ', ' jpeg ');//settings attached Item upload type            $upload->savepath = ' 1/';//Set Attachments upload directory            //upload file            $info = $upload->upload ();            if (! $info) {//Upload error message                $this->error ($upload->geterror ());            } else {//upload succeeded                $this->success (' Upload success! ', U (' index/index1 '));            }


Pictures uploaded successfully How to display:


Reply to discussion (solution)

Upload the image storage path to a field in the database and call this field when the page is displayed.

Landlord since the upload success is estimated that the path of the picture is not to see the file path to upload a comparison, not to solve it?

Stitching path. When storing or outputting, the path output is based on the actual physical location.
The old version of TP has a problem with the upload class, upgrade to the latest version to

if (! $upload->upload ()) {//Upload error message $this->error ($upload->geterrormsg ());} else{//upload successfully obtained upload file information $info =  $upload->getuploadfileinfo ();}//Save form data $user = M ("user");//Instantiate User Object $user-> Create (); Create data Object $user->photo = $info [0][' Savename ']; Save uploaded photos Assemble $user->add () as needed; Write user data to database $this->success (' Data 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.