duandgfh0506 2013-03-12 15:18
浏览 54
已采纳

将图像文件发送到php

I can't seem to get past isset($_FILES['formFile']) in my php file, it always returns false. I'm using Ext js 4.1 My goal is to store these images in a blob.

Extjs code:

  var fi = new Ext.FormPanel({            
        fileUpload: true,
        width: 400,
        frame: false,            
        autoHeight: true,            
        labelWidth: 40,
        border: false,            
        margins: '10 0 0 10',
        defaults: {
            anchor: '95%',
            allowBlank: false,
            msgTarget: 'side',
            border: false
        },
        items: [{
            xtype: 'filefield',                
            emptyText: 'Select an image',
            fieldLabel: 'Image',
            id: 'formFile',
            buttonCfg: {
                text: '',
                iconCls: 'upload-icon'
            },
            border: false
        }],
        buttons: [{
            text: 'Upload',
            handler: function(){
                var form = this.up('form').getForm();                    
                if(form.isValid()){
                    form.submit({
                        url: 'php/picture-upload.php',
                        waitMsg: 'Uploading your image...',
                        success: function(fi, o){                                
                            alert('succes');
                        }
                    });
                }
            }
        }]
    });

php:

if (!isset($_FILES['formFile'])) {
echo '<p>Please select a file</p>';
echo '{"success": false}';
} else {
try {
    upload();
    echo '<p>Thank you for submitting</p>';
} catch (Exception $e) {
    echo $e->getMessage();
    echo 'Sorry, could not upload file';
}
}

the output of print_r($_FILES);

Array
(
[formFile-inputEl] => Array
    (
        [name] => clicla.jpg
        [type] => image/jpeg
        [tmp_name] => /Applications/MAMP/tmp/php/phpnUxgV3
        [error] => 0
        [size] => 6772
    )
  • 写回答

1条回答 默认 最新

  • duanqinqiao4844 2013-03-12 15:19
    关注

    isset should be checking for formFile-inputEl based on your output.

    if (!isset($_FILES['formFile-inputEl'])) {
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试