一. 在控制器中写一个方法,用于上传
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 style="max-width:90%" src="__PUBLIC__/uploads/1.jpg" alt="ThinkPHP322 无刷新上传插件uploadify 使用" ></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 style="max-width:90%" src='__PUBLIC__/Uploads/"+data+"' alt="ThinkPHP322 无刷新上传插件uploadify 使用" >";
$('#imgs').html(img);
}
});
</script>
</html>以上就介绍了ThinkPHP322 无刷新上传插件uploadify 使用,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号