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! '); }