uploadify多图片和文件上传网站应用

先要下载压缩包

www.uploadify.com/wp-content/uploads/files/uploadify.zip

1,模板文件引用

<!--引用jquery uploady*}-->
<script src="http://www.hq08.cn/public/jquery.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="http://www.hq08.cn/public/uploadify.css" media="all">
<script type="text/javascript" src="http://www.hq08.cn/public/jquery.uploadify.min.js"></script>
<!-- uploadify相关设置 -->
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'formData' : {
'timestamp' : '{#$timestamp#}',
'token' : '{#$token#}'
},
//在php下应用的时候请务必加上这些代码,避免使用出错
'buttonText':'上传',
'multi': true,//允许多文件上传
'swf' : "public/uploadify.swf",
'uploader' : '{#spUrl c=heji a=uploadify#}',
'onUploadSuccess': function (file, data, response) {
$('.touxiang_path').val(data);
}
});
});
</script>

2.代码添加几行代码

<div class="touxiang">
<input id="file_upload" type="text" name="touxiang">
</div>

<div class="touxiang_path">
<input id="" type="text" name="touxiang_path" class="touxiang_path" style="width: 500px;">
</div>

可以任意修改样式,可以更加美观

3,php上传处理

 $targetFolder = '/up/'; 

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $handler_dir.'/'. $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);

if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}

可以设置图片和文件大小,可以加水印,缩略图,任意处理图片等

猜你喜欢

转载自www.cnblogs.com/96net/p/9392158.html
今日推荐