Thinkphpftp file upload problems how to use thinkphp's built-in ftp file Upload? I want to upload videos and images, but it still doesn't work. I read the manual, but I don't quite understand it. if there is a better example, thank you,
Reply to discussion (solution)
The thinkphp official website provides examples for uploading files.
Function album_add () {if (! Session ('? User ') {$ this-> error (' no operation permission! ', "", 3);} if (IS_POST) {$ 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 $ d_root = $ _ SERVER ['document _ root']; $ upload-> rootPath = $ d_root. '/upload/album/'; // sets the root directory for uploading attachments $ upload-> savePath = ''; // sets the attachment upload (child) directory // upload file $ info = $ upload-> upload (); $ images = ""; $ cover_image = ""; $ index_cover = ""; if (! $ Info) {// upload error message $ this-> error ($ upload-> getError ();} else {if (is_array ($ info )) {foreach ($ info as $ key => $ value) {if (strpos ($ key, "album_cover_add ")! = FALSE) {$ cover_image = '/upload/album /'. $ value ['savepath']. $ value ['savename']; $ thumb_image_path = '/upload/album /'. $ value ['savepath']. 'admin _ cover/'; $ image_name = $ value ['savename']; create_dir ("$ d_root. $ thumb_image_path "); $ image = new \ Think \ Image (); $ image-> open (" $ d_root $ cover_image "); // Generate a pie chart with a center crop of 150*150,150 and save it as thumb.jpg $ image-> thumb (, \ Think \ Image: IMAGE_THUMB_CENTER)-> sav E ("$ d_root $ thumb_image_path $ image_name"); $ admin_cover_path = $ thumb_image_path. $ image_name;} else {$ images. = '/upload/album /'. $ value ['savepath']. $ value ['savename']. "|"; $ images_path = '/upload/album /'. $ value ['savepath']. $ value ['savename']; $ index_cover_path = '/upload/album /'. $ value ['savepath']. 'index _ cover/'; $ image_name = $ value ['savename']; create_dir ("$ d_root. $ index_cover_p Ath "); $ image = new \ Think \ Image (); $ image-> open (" $ d_root $ images_path "); // generate an image with a center crop of 150*150,150 and save it as thumb.jpg $ Image-> thumb (, \ Think \ image: IMAGE_THUMB_CENTER)-> save ("$ d_root $ index_cover_path $ image_name "); $ index_cover. = $ index_cover_path. $ image_name. "|" ;}}}$ nowTime = date ('Y-m-d h: I: S', time ()); $ a ['title'] = I ('post. album_title_add'); $ a ['cover _ image'] = $ admin_cover_path; $ a ['I Ndex_cover_image '] = $ index_cover; $ a ['images'] = $ images; $ a ['add _ time'] = $ nowTime; $ a ['last _ update_time '] = $ nowTime; $ album = M ("album"); $ album-> create ($ ); $ result = $ album-> add (); if ($ result) {// address of the page to jump to after the setting is successful, the default returned page is $ _ SERVER ['http _ referer'] $ this-> success ('Album published successfully! ', "Album_list", 3);} else {// The default redirect page of the error page is to return to the previous page. Generally, you do not need to set $ this-> error ('Album Publishing failed! ', "", 5) ;}} else {$ this-> display ("album_add") ;}} page Template:
Thank you for your solution ~~