Home >Backend Development >PHP Tutorial >ThinkPHP322 refresh-free upload plug-in uploadify use
1. Write a method in the controller for uploading
public function upload(){ if (!empty($_FILES)) { //图片上传设置 $config = array( 'maxSize' => 3145728, 'rootPath' => 'Public', 'savePath' => '/Uploads/', 'saveName' => array('uniqid',''), 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'autoSub' => false, 'subName' => array('date','Ymd'), ); $upload = new \Think\Upload($config);// 实例化上传类 $images = $upload->upload(); //判断是否有图 if($images){ $info=$images['Filedata']['savename']; //返回文件地址和名给JS作回调用 echo $info; } else{ $this->error($upload->getError());//获取失败信息 } } }2. Template
<html> <head> <meta http-equiv="content-type" c/html; charset=utf-8"> <title>Index</title> <link rel="stylesheet" href="__PUBLIC__/uploadify.css"> <script src='__PUBLIC__/jquery.js'></script> <script src='__PUBLIC__/jquery.uploadify.min.js'></script> </head> <body> <div id="imgs"><img width="200px" src="__PUBLIC__/uploads/1.jpg"></div> <input id="file_upload" name="file_upload" type="file" multiple="true" value="" /> </body> <script> var img = ''; $('#file_upload').uploadify({ 'swf' : '__PUBLIC__/uploadify.swf', 'uploader' : '{:U("Index/upload")}', //上传的方法 'buttonText' : '缩略图上传', 'onUploadSuccess' : function(file, data, response) { //把所有上传的图片都放入DIV中 img += "<img width='200px' src='__PUBLIC__/Uploads/"+data+"'>"; $('#imgs').html(img); } }); </script> </html>
The above introduces the use of the ThinkPHP322 refresh-free upload plug-in uploadify, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.