我使用uploadify,everthing工作正常,但我坚持服务器端验证,
假设用户上传多个文件,如果所有文件的总大小超过15 MB,那么我需要在屏幕上抛出最大限制为15 mb的错误。是否可以在Uploadify中
我尝试过的代码:
HTML:
<form>
<div id="div_errorLog"></div>
<div id="queue"></div>
<input id="file_upload" name="file_upload" type="file" multiple="true">
</form>
<script type="text/javascript">
<?php $timestamp = time();?>
$(function() {
$('#file_upload').uploadify({
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'auto' : true,
'fileTypeExts' : '*.jpg; *.mp3; *.wma; *.wav; *.m4a; *.amr; *.3ga; *.flv; *.mov; *.dat;*.avi;*.mpeg; *.ram; *.mp4; *.wmv; *.asf; *.swf; *.m3u; *.3gp; *.mpg; *.divx; *.rm; *.pps; *.zip; *.rar; *.gz; *.txt; *.exe; *.msi; *.tgz; *.scr; *.dot; *.docx; *.chm;*.jar; *.torrent; *.xlsx; *.ngr; *.7z; *.001; *.002; *.003; *.004; *.005; *.006; *.007;*.008; *.009; *.010; *.011; *.012; *.013; *.014;*.015; *.016; *.017; *.018; *.019; *.020; *.ai; *.psd; *.cdr; *.pptx; *.apk; *.ipa; *.pkg; *.cbr; *.cbz',
'fileSizeLimit' : '15360KB',
'multi' : false,
'uploader' : 'uploadify.php',
'queueSizeLimit' : 1,
'uploadLimit' : 1,
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
},
'onUploadSuccess' : function(file, data, response) {
alert('The file ' + file.name + ' was successfully uploaded');
window.location.replace("");
}
});
});
</script>
uploadify.php
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$var_UniqueFileName = strtotime("now").'_'.$_FILES["Filedata"]["name"];
$targetFile = "uploads/".$var_UniqueFileName;
// Validate the file type
$fileTypes = array("mp3", "wma", "wav", "m4a", "amr", "3ga", "flv", "mov", "dat", "avi",
"mpeg", "ram", "mp4", "wmv", "asf", "swf", "m3u", "3gp", "mpg", "divx", "rm", "vob",
"rmvb", "f4v", "jpg", "jpeg", "gif", "bmp", "png", "doc", "csv", "xls", "rtf", "ppt",
"pdf", "pps", "zip", "rar", "gz", "txt", "exe", "msi", "tgz", "scr", "dot", "docx", "chm",
"jar", "torrent", "xlsx", "ngr", "7z", "001", "002", "003", "004", "005", "006", "007", "008",
"009", "010", "011", "012", "013", "014", "015", "016", "017", "018", "019", "020", "ai", "psd",
"cdr", "pptx", "apk", "ipa", "pkg", "cbr", "cbz"); // 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.';
}
}
如何实施服务器端验证?