2013-09-23 55 views
1

我在EXTJS(http://dev.sencha.com/deploy/dev/examples/form/file-upload.html)中使用UploadFile示例,并且出现错误。EXTJS&PHP上传文件2

ExtJS的:

var loadfile = new Ext.FormPanel({ 
    fileUpload: true, 
    width: 500, 
    frame: true, 
    title: 'Добавить фотографию', 
    autoHeight: true, 
    bodyStyle: 'padding: 10px 10px 0 10px;', 
    labelWidth: 50, 
    defaults: { 
     anchor: '95%', 
     allowBlank: false, 
     msgTarget: 'side' 
    }, 
    items: [ 
    { 
     xtype: 'fileuploadfield', 
     id: 'form-file', 
     emptyText: 'Выберите фотографию', 
     fieldLabel: 'Фото', 
     name: 'userfile', 
     buttonText: 'Открыть' 
    }], 
    buttons: [{ 
     text: 'Сохранить', 
     handler: function(){ 
      if(loadfile.getForm().isValid()){ 
    //alert('Имя: '+loadfile.getForm().findField('userfile').getValue()); 
        loadfile.getForm().submit({ 
         url: '/test/file-upload.php', 
         waitMsg: 'Сохранение фотографии...', 
         success: function(loadfile, o){ 
          msg('Success', 'Processed file "'+o.result.file+'" on the server'); 
         } 
        }); 
      } 
     } 
    },{ 
     text: 'Сброс', 
     handler: function(){ 
      loadfile.getForm().reset(); 
      } 
      }] 
     }); 

文件upload.php的:

$uploaddir = '/var/lib/tomcat6/webapps/test/upload/000'//.$_GET["path"]; 
if (!is_dir($uploaddir)) 
    { 
    mkdir($uploaddir, 0777); 
    } 
$uploaddir.='/'; 
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . 
    $_FILES['userfile']['name'])) { 
echo $uploaddir; 
} else { 
echo "error"; 
} 

和我在EXT-all.js错误:

Uncaught SyntaxError: Unexpected token <

回答

1

Uncaught SyntaxError: Unexpected token <

此错误出现当你的PHP代码在HTML中引发错误时,ExtJS期待JSON作为回报,为了得到更进一步的信息,您需要打开javascript调试器并检查XHR的响应,其中一个请求会为您提供有关错误的更多信息。

+0

我资助这个:“

<?php $uploaddir = '/var/lib/tomcat6/webapps/test/upload/'//.$_GET["path"]; ....... } ?> 
” – user15445

+0

看起来你的服务器没有处理PHP,只是将它作为纯文本返回。你确定mod_php是在apache中启用的吗? – NDM

+0

apache是​​的,但这个HTML从tomcat6开始 – user15445