简体   繁体   English

将图像文件发送到php

[英]Send image file to php

I can't seem to get past isset($_FILES['formFile']) in my php file, it always returns false. 我似乎无法在我的php文件中过去isset($ _ FILES ['formFile']),它总是返回false。 I'm using Ext js 4.1 My goal is to store these images in a blob. 我正在使用Ext js 4.1我的目标是将这些图像存储在blob中。

Extjs code: Extjs代码:

  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: 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); print_r的输出($ _ FILES);

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

isset should be checking for formFile-inputEl based on your output. isset应根据您的输出检查formFile-inputEl。

if (!isset($_FILES['formFile-inputEl'])) {
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM