Jquery 上传&;CakePHP-一些上传不';不要向服务器发送任何数据
我正在使用Uploadify在我的CakePHP应用程序中处理上传。有些上传效果很好 以下是我的javascript代码:Jquery 上传&;CakePHP-一些上传不';不要向服务器发送任何数据,jquery,cakephp,cakephp-1.3,uploadify,Jquery,Cakephp,Cakephp 1.3,Uploadify,我正在使用Uploadify在我的CakePHP应用程序中处理上传。有些上传效果很好 以下是我的javascript代码: <script type="text/javascript"> $(document).ready(function() { $('.submit input').attr('disabled','disabled'); $('#uploadify').uploadify({ 'uploader' : '/uploadify/uploa
<script type="text/javascript">
$(document).ready(function() {
$('.submit input').attr('disabled','disabled');
$('#uploadify').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/videos/ajaxUpload',
'cancelImg' : '/uploadify/cancel.png',
'folder' : '/files/video',
'auto' : true,
'multi' : true,
'sizLimit' : 31457280,
'onComplete': function(event,id,fileObj,response,data){
console.log(fileObj);
var responseObj = $.parseJSON(response);
console.log(responseObj);
$('#upload-complete').html(responseObj.message);
$('#VideoName').val(responseObj.name);
$('.submit input').attr('disabled',false);
},
'buttonText': 'CHOOSE FILE',
'fileExt' : '*.mp4;*.mpg;*.mpeg;*.mov;*.avi;*.mpv2;*.qt;*.flv;'
});
});
</script>
}
对于小于8MB的文件,这一切都像一个符咒,但对于大于8MB的文件,控制器会说“没有收到文件数据”,表示$\u文件为空。这很奇怪-如果文件超出php.ini中的某个指令,我会预料到其他错误之一
有人能帮忙吗?问题在于
post\u max\u size
ini指令,默认设置为8MB。如果上载的文件超过此值,则不会引发错误,只会导致所有超全局文件(例如$\u FILES
和$\u POST
)为空
它还会将警告打印到日志文件中。但与标准输出无关
您无法直接检测是否超过了post\u max\u size
。你只能根据你对超球的期望和你得到的来猜测
另一方面,通过检查
$\u文件['userfile']['error']
是否存在错误,您可以通过编程检测是否超出了上载文件的最大大小。嗨,Ben,谢谢您的回答,但在这种情况下,$\u文件肯定不会为空,因此服务器不会返回“未收到文件数据”,而是返回“文件超过了最大文件大小”?您使用的是小于4.2的php版本吗?在4.2之前,当超过post_max_大小时,$_文件将完全为空,并且不包含任何错误消息。而且由于您说“大约8mb”“是问题发生的地方,症状完全符合post_max_尺寸。我仍然相信这就是问题所在。另外,请检查您的日志文件以获取警告。不管你的php版本如何,它都会显示出来。谢谢-添加了一个自定义的php.ini,大小为50米。不过,我使用的是PHP5.3,你有没有想过为什么$\u文件不包含错误(或任何其他内容)?
public function ajaxUpload(){
$this->autoRender = false;
$name = $type = $size = $status = false;
$message = 'There was a problem uploading the file';
if (!empty($_FILES)) {
if ($_FILES['Filedata']['error'] == 0){
$allowedTypes = array(
'mp4',
'mpg',
'mpeg',
'mov',
'avi',
'mpv2',
'qt',
'flv'
);
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$allowedTypes)){
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = WWW_ROOT . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
$name = array_pop(explode('/',$targetFile));
$type = $_FILES['Filedata']['type'];
$size = $_FILES['Filedata']['size'];
$status = 1;
$message = 'File successfully uploaded';
}else{
$status = 0;
$message = 'Invalid file type.';
}
}else{
$status = 0;
switch($_FILES['Filedata']['error']){
case 1:
$message = 'File exceeded max filesize';
break;
case 2:
$message = 'File exceeded max filesize';
break;
case 3:
$message = 'File only partially uploaded';
break;
case 4:
$message = 'No file was uploaded';
break;
case 7:
$message = 'There was a problem saving the file';
break;
default:
$message = 'There was a problem uploading the file';
break;
}
}
}else{
$status = 0;
$message = 'No file data received.';
}
echo json_encode(
array(
'status'=>$status,
'name'=>$name,
'type'=>$type,
'size'=>$size,
'message'=>$message
)
);