2013-09-23 4 views
1

Я использую пример UploadFile в EXTJS (http://dev.sencha.com/deploy/dev/examples/form/file-upload.html), и у меня есть ошибка.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

i fund this: "

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

+0

похоже, что ваш сервер не обрабатывает PHP и просто возвращает его как обычный текст. вы уверены, что mod_php включен в apache? – NDM

+0

apache да, но этот html начать с tomcat6 – user15445

Смежные вопросы