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.‘;
}
}
可以設置圖片和文件大小,可以加水印,縮略圖,任意處理圖片等
uploadify多圖片和文件上傳網站應用