一. 在控制器中寫一個方法,用於上傳
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());//获取失败信息 } } }
<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>
以上就介紹了ThinkPHP322 無刷新上傳插件uploadify 使用,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。