Extjs+ php文件上传错误-试图解码无效的JSON字符串:


Extjs+PHP-File upload error- trying to decode an invalid JSON String:

我在extjs+PHP[yii框架]工作。我正在研究文件上传控制。我的视图代码为-

Ext.define('Balaee.view.kp.dnycontent.Content', 
{
    extend:'Ext.form.Panel',
    requires:[
              'Balaee.view.kp.dnycontent.ContentView'
              ],
    id:'ContentId',
    alias:'widget.Content',
    enctype : 'multipart/form-data', 
    title:'This day in a history',
    items:[
        {
        xtype: 'fileuploadfield',
        hideLabel: true,
        emptyText: 'Select a file to upload...',
        //inputType: 'file',
        id: 'upfile',
        name:'file',
        width: 220
}],
   buttons: [{
        xtype : 'button',
        fieldlabel:'upload',
        action:'upload',
        name:'upload',
        text: 'Upload',
        formBind:'true',
       handler: function() {
            var form = this.up('form').getForm();
            if(form.isValid()){
                form.submit({
                    url: 'index.php/QuestionBank/Qbpaper/getFile',
                    waitMsg: 'Uploading your photo...',
                  //  uploadPath:'/app/model',
                    success: function(fp, o) {
                        Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.');
                    }
                });} } }]});
我已经写了上面的代码从extjs4发送文件。我的服务器端是在PHP [Yii框架]。对于服务器端,我已经编写了代码来接收这个文件-
public function actiongetFile()
    {
        $fileName = $_FILES['upfile']['name'];
        $fileSize = $_FILES['upfile']['size'];
        $fileType = $_FILES['upfile']['type'];
        $fp      = fopen($fileName, 'r');
        $content = fread($fp, filesize($fileName));
        $content = addslashes($content);
        fclose($fp);
        if(!get_magic_quotes_gpc()){
            $fileName = addslashes($fileName);
        }

但是服务器端代码不能正常工作。当从extjs发送文件时,它给出的错误是-"Ext. js"。错误:您正在尝试解码无效的JSON字符串:PHP的通知未定义索引:upfile "在php中如何访问通过extjs4发送的文件。

name:'file'

THIS ^是你的文件在数组中的索引。

id是内部的,但name是提交的标签。

试试。用途:

$_FILES['file']['name']

代替:

$_FILES['upfile']['name']