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