日期:2014-05-17 浏览次数:20556 次
$(function() {
$('#file_upload').uploadify({
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php',
'buttonText':'上传',
'auto' : false,
'height': 24,
'width': 50,
'cancelImage': 'uploadify-cancel.png',
'checkExisting':'check-exists.php',
'multi':false,
'fileDataName': 'Filedata',
'fileTypeDesc': 'FLV视频文件和图片文件',
'fileTypeExts':'*.flv;*.jpg;*.iso',
'onUploadError' : function(file,errorCode,errorMsg,errorString,swfuploadifyQueue){
alert(errorMsg);//上传文件出错是触发(每个出错文件触发一次)
},
'onUploadSuccess':function(file,data,response){
alert( 'id: ' + file.id+ ' - 索引: ' + file.index+ ' - 文件名: ' + file.name + ' - 文件大小: ' + file.size+ ' - 类型: ' + file.type+ ' - 创建日期: ' + file.creationdate+ ' - 修改日期: ' + file.modificationdate+ ' - 文件状态: ' + file.filestatus + ' - 服务器端消息: ' + data+ ' - 是否上传成功: ' + response);
}
// Your options here
});
});
$targetFolder = '/uploads'; // Relative to the root
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png','flv','iso'); // 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.';
}
}