$ _FILES是空的

时间:2011-05-07 08:01:50

标签: php jquery ajax file-upload

我正在使用Ajax file upload bt $ _FILES总是空的。

这是我的php页面

    include('../../inc/functions.php');
    $allowdExt = array("mp4","flv");
    $uploaddir = '../../uploads/videos/';
    $filename = basename($_FILES['uploadv']['name']);
    echo "file: $uploaddir".$filename ;
    exit;

        $extension = getExtension($filename);
        $extension = strtolower($extension);

        if(!in_array($extension,$allowdExt)){
            $errors =1;
        }
        else
        {
            $file_name = MakeRandomChars().'.'.$extension ;
            $newname=$uploaddir.$file_name;
            $copied = move_uploaded_file($_FILES['uploadv']['tmp_name'], $newname);
            if (!$copied)
            {
                $errors =1;
            }
        }

        if( $errors == 1){
            echo "0";
        }else{
            echo $file_name;
        }

这是我的jquery代码:

$(function(){
    var btnUpload=$('#uploadVideo');
    var status=$('#status');
    new AjaxUpload(btnUpload, {
        action: 'pages/upload-video.php',
        name: 'uploadv',
        onSubmit: function(file, ext){
             if (! (ext && /^(flv|mp4)$/.test(ext))){ 
                status.text('Only Flv,Mp4 files are allowed');
                return false;

            }
            $('#wait').fadeIn();
        },
        onComplete: function(file, response){
            status.text('');
            if(response != "0"){
                $('#wait').fadeOut();
                $('#videoIcon').fadeIn();
                $('#status').attr('video',response);
            }
        }
    });     
});

1 个答案:

答案 0 :(得分:2)

使用ajaxupload,您需要从原始php输入中获取数据,而不是从$_FILES

获取

您可以在此处查看示例:https://github.com/valums/file-uploader/blob/master/server/php.phpqqUploadedFileXhr类)