How to upload files in thinkphp

Source: Internet
Author: User
In thinkphp, how does one process uploaded files? in thinkphp, how does one process uploaded files? that is, all files must be processed. I made a website to upload all the files including images, txt files, doc files, and videos. How can I upload and insert data to a database? $ MM (& quot; file & quot;); $ _ cleanarray (); if (! Empty ($ _ FILES) {& nbsp; $ I thinkphp
How to process uploaded files in thinkphp, that is, to process all files. I made a website to upload all the files including images, txt files, doc files, and videos. How can I upload and insert data to a database?
$ M = M ("file ");
// $ _ Clean = array ();
If (! Empty ($ _ FILES )){
$ Im = $ this-> _ upload ();
$ _ POST ["filename"] = $ im;
$ _ POST ["uptime"] = time ();

}

$ N = $ m-> add ();
If ($ n ){
$ Str = "added successfully ";
} Else {
$ Str = "failed to add ";
}
$ This-> assign ("str", $ str );
$ This-> display ("upload ");
}

// File Upload
Protected function _ upload (){
Import ("@. ORG. UploadFile ");
$ Upload = new UploadFile ();
// Set the size of the uploaded file
$ Upload-> maxSize = 3292200;
// Set the Upload file type
$ Upload-> allowExts = explode (',', 'jpg, gif, png, jpeg, pjpeg, bmp, doc, rar, txt ');
// Set the attachment Upload Directory
$ Upload-> savePath = './Public/upload /';
// Set file Upload rules
$ Upload-> saveRule = uniqid;
If (! $ Upload-> upload ()){
// Capture Upload exceptions
$ This-> error ($ upload-> getErrorMsg ());
} Else {
// Obtain the information of the successfully uploaded File
$ UploadList = $ upload-> getUploadFileInfo ();
// Import ("@. ORG. Image ");
// Add a watermark to the m _ thumbnail. Image: water ('original filename ', 'watermark Image address ')
/* Image: water ($ uploadList [0] ['savepath'].'m _'. $ uploadList [0] ['savename'], '/thinkphp_2.20.full_with_extend/Examples/File/Tpl/default/Public/Images/logo2.png ');*/
Return $ uploadList [0] ['savename'];
}

} I cannot handle this.

------ Solution --------------------
Http://thinkphp1.cn/Manual/170
------ Solution --------------------
Isn't thinkphp a demo?
------ Solution --------------------
$ Upload-> savePath = './Public/upload /';
Change
$ Upload-> savePath = './upload /';
Try it

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.