Home > Backend Development > PHP Tutorial > ThinkPHP322 refresh-free upload plug-in uploadify use

ThinkPHP322 refresh-free upload plug-in uploadify use

WBOY
Release: 2016-07-29 08:59:38
Original
936 people have browsed it

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());//获取失败信息
            }
        }
    }
Copy after login
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/"&#43;data&#43;"'>";
	            $('#imgs').html(img);
        	}
    	});
    </script>
</html>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template