ThinkPHP uploads images smoothly, but the database field content is NULL
Source: Internet
Author: User
The image is successfully uploaded in ThinkPHP, but the database field content is NULLThinkPHP, but the database field content is NULL & nbsp; Public & nbsp; function & nbsp; upload () {& nbsp; the image is successfully uploaded in impo ThinkPHP, but the database field content is NULL.
The image is successfully uploaded in ThinkPHP, but the database field content is NULL.
Public function upload (){
Import ('org. Net. uploadfile ');
$ Upload = new UploadFile (); // instantiate the upload class
$ Upload-> maxSize = 3145728; // sets the attachment upload size.
$ Upload-> allowExts = array ('jpg ', 'GIF', 'PNG', 'jpeg '); // you can specify the attachment upload type.
$ Upload-> savePath = './Public/Uploads/'; // sets the attachment upload Directory
If (! $ Upload-> upload () {// upload error message
$ This-> error ($ upload-> getErrorMsg ());
} Else {// the uploaded file is successfully obtained.
$ Info = $ upload-> getUploadFileInfo ();
}
// Save the form data, including the attachment data
$ User = M ("Photo"); // instantiate the User object
$ User-> create (); // create a data object
$ User-> photo = $ info [0] ['tuian']; // Save the uploaded photo and assemble it as needed
$ User-> add (); // write User data to the database
$ This-> success ('Data Is saved successfully! ');
}
How to rename the uploaded image and insert it into the database? upload the image database thinkphp and share it:
------ Solution --------------------
By
"Savepath" => "./Public/Uploads /"
"Savename" => "444.jpg"
Yes
$ User-> photo = substr ($ info [0] ['savepath'], 1). $ info [0] ['savename'];
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