我有一个带Uploadify字段的简单表单,可以上传多张图片。但是,当我选择我的文件时,它似乎没有做任何事情(并且它们被添加到队列中)并且我在控制台中没有输出。
这是我的HTML:
<script>
$(function() {
$('#file_upload').uploadify({
uploader: '/cms/tpl/swf/uploadify.swf',
script: '/cms/inc/upload_image.php?album=39',
cancelImg: '/cms/tpl/img/cross.gif',
folder: '/tpl/uploads',
multi: true,
auto: true,
fileExt: '*.jpg;*.gif;*.png',
fileDesc: 'Image files (.jpg, .gif, .png)',
queueID: 'file_queue',
queueSizeLimit: 10,
simUploadLimit: 10,
sizeLimit: 1048576,
removeCompleted: false,
scriptData: {
'album': '39',
'session': 'aeac944c4e911edc5e5de10c98b8e5b7'
},
onError: function(a,b,c,d) {
console.log(a);
console.log(b);
console.log(c);
console.log(d);
},
onSelectOnce: function(event,data) {
$('#status_message').text(data.filesSelected + ' files have been added to the queue.');
},
onComplete: function(a,b,c,d,e) {
if (d !== '1') {
alert(d);
}
else {
alert('Filename: ' + c.name + ' was uploaded');
}
},
onAllComplete: function(event, data) {
$('#status_message').text(data.filesUploaded + ' files uploaded; ' + data.errors + ' errors.');
}
});
});
</script>
这是我用来处理文件上传的服务器端脚本(PHP):
<?php
/**
* @todo Validation!
*/
if (isset($_POST) && isset($_FILES['Filedata'])) {
$upload_dir = '../../tpl/uploads/';
$source = $_FILES['Filedata']['tmp_name'];
$filename = sprintf('%s.%s', uniqid(), $mime[$_FILES['Filedata']['type'][$name.'_upload']]);
$destination = $this->uploads_dir.$filename;
require '../../inc/database.php';
require '../../inc/globals.php';
if (move_uploaded_file($source, $destination)) {
try {
$sql = "INSERT INTO gallery_images (album, image) VALUES (?,?)";
$smt = $pdo->prepare($sql);
$res = $smt->execute(array($_REQUEST['album'], $filename));
}
catch (PDOException $e) {
// send error message
}
}
switch ($_FILES['Filedata']['error']) {
case 0:
// $msg = 'File successfully uploaded';
break;
case 1:
case 2:
$msg = 'File size exceeds limit';
break;
case 3:
$msg = 'The file was only partially uploaded';
break;
case 4:
$msg = 'No file was specified';
break;
case 6:
$msg = 'The temporary folder could not be found';
break;
case 7:
$msg = 'Failed to write the file to disk';
break;
case 8:
$msg = 'File upload stopped by extension';
break;
default:
$msg = 'Unknown error';
break;
}
if ($msg) {
$stringData = "Error: ".$_FILES['userfile']['error']." Error Info: ".$msg;
}
else {
$stringData = "1"; // This is required for onComplete to fire on Mac OSX
}
echo $stringData;
}
非常简陋,但做得很好。难道我做错了什么?有没有我错过的东西?在查看了Uploadify演示页面之后,将上述内容放在一起。
答案 0 :(得分:0)
我猜你可能正在使用jQuery.noConflict()方法不是吗?我有类似的问题,我的文件没有事件最终在文件队列中...也没有输出到控制台... 我怀疑jQuery.noConflict ...在我的情况下...也许我的心态可能会帮助你:))