Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 上载文件(附件)错误_Php_Extjs_File Upload_Zend Framework2 - Fatal编程技术网

Php 上载文件(附件)错误

Php 上载文件(附件)错误,php,extjs,file-upload,zend-framework2,Php,Extjs,File Upload,Zend Framework2,我在保存到表单和datagrid时出错 我不知道,是什么错误? 我使用ExtJS4和zend framework 2 这是消息错误: sourceClass: "Ext.JSON", sourceMethod: "decode", msg: "You're trying to decode an invalid JSON String: Wa…session":true, "other":null,"processingTime":null}", message: "You're tryi

我在保存到表单和datagrid时出错 我不知道,是什么错误? 我使用ExtJS4和zend framework 2

这是消息错误:

sourceClass: "Ext.JSON", 
sourceMethod: "decode", 
msg: "You're trying to decode an invalid JSON String: Wa…session":true,
"other":null,"processingTime":null}", 
message: "You're trying to decode an invalid JSON String: Wa…session":true,
"other":null,"processingTime":null}"}
message: "You're trying to decode an invalid JSON String: 
Warning: Invalid argument supplied for foreach() in Purchase.php on line 331↵
{"success":false,"data":{"no_po":null,"date_po":null,"supplier":null,"shipping_to":null,"total_price_head":null,"vat":null,"net_price":null,"id_po":null,"file_ext":"png","file_type":"image\/png","file_size":633237,"file_name":"2015-02-23-Negative-World-left-hand.png"},"messages":[],"pageSize":null,"start":null,"total":null,"session":true,"other":null,"processingTime":null}"
msg: "You're trying to decode an invalid JSON String: 
Warning: Invalid argument supplied for foreach() in Purchase.php on line 331↵
{"success":false,"data":{"no_po":null,"date_po":null,"supplier":null,"shipping_to":null,"total_price_head":null,"vat":null,"net_price":null,"id_po":null,"file_ext":"png","file_type":"image\/png","file_size":633237,"file_name":"2015-02-23-Negative-World-left-hand.png"},"messages":[],"pageSize":null,"start":null,"total":null,"session":true,"other":null,"processingTime":null}"
sourceClass: "Ext.JSON"
sourceMethod: "decode"
这是我的代码:

Purchase.php

public function savePurchaseOrder($header,$detail)
{
    header('Content-Type: text/html');
    try{

        if(!$this->_user_id){
            $this->result->messages[] = 'Session Expired, Please re-login';
            return;
        }

        $_header = Zend_Json::decode($header, Zend_Json::TYPE_ARRAY);
        $_detail = Zend_Json::decode($detail, Zend_Json::TYPE_ARRAY);

        $userLogin = $this->_user_id;

        $table_header = new Zend_Db_Table('vending_tr_purchase_product_order_id');
        $table_detail = new Zend_Db_Table('vending_tr_purchase_product_order');
        $table_detail_pr = new Zend_Db_Table('vending_tr_purchase_product');
        //print_r($_detail);

    if (isset($_FILES['file_path']))
    {
            $errors = array();
            // define file attribute
            $file_name = $_FILES['file_path']['name'];
            $file_size = $_FILES['file_path']['size'];
            $file_tmp  = $_FILES['file_path']['tmp_name'];
            $file_type = $_FILES['file_path']['type'];
            $file_ext  = strtolower(end(explode('.', $_FILES['file_path']['name'])));

        $_newdata = array(
            'no_po' => $_header['no_po'],
            'date_po' => $_header['date_po'],
            'supplier' => $_header['supplier'],
            'shipping_to' => $_header['shipping_to'],
            'total_price_head' => $_header['total_price_head'],
            'vat' => $_header['vat'],
            'net_price' => $_header['net_price'],
            'id_po' => $_header['id_po'],
            //'file_path' => $_header['file_path'],
            'file_ext' => $file_ext,
            'file_type' => $file_type,
            'file_size' => $file_size,
            'file_name' => $file_name

        );

        $ext = array(
                "bmp",
                "jpeg",
                "jpg",
                "png",
                "gif",
                "xls",
                "xlsx",
                "doc",
                "docx",
                "pdf",
                "ppt",
                "pptx",
                "zip",
                "rar",
                "txt",
                "rtf"
        );
            // check the extension type on upload process
            if (in_array($file_ext, $ext) === false)
            {
                $errors[] = 'File format "' . $file_ext . '" is not allowed';
                return $this->result->messages[] = $errors;
            }
            // check the file size is not more than 25 MB = 26214400 bytes, 1 MB = 1048576 bytes
            if ($file_size > 26214400)
            {
                $errors[] = 'Sorry, the allowed max size is 25 MB';
                return $this->result->messages[] = $errors;
            }

        if($_header['action'] == 'C'){
            $record = array_merge($_newdata, array(
                'row_created_by' => $userLogin,
                'row_created_datetime' => date("YmdHis", strtotime($this->_datetime))
            ));
            $table_header->insert($record);
            $header_id = $this->_db->lastInsertId();
            $this->result->success = true;
        }

        if($_header['action'] == 'U'){
            $where = array("id_po = " . $this->_db->quote($_header['id_po']));
            $record = array_merge($_newdata, array(
                'row_changed_by' => $userLogin,
                'row_changed_datetime' => date("YmdHis", strtotime($this->_datetime))
            ));
            $table_header->update($record,$where);
            $this->result->success = true;
        }

        foreach ($_detail as $key) {

            $this->_db->beginTransaction();
            //$key['data']['warehouse'] = $_header['warehouse'];

            $_insertDetail = array(
                'qty_order' => $key['data']['qty_order'], 
                'no_pr' => $key['data']['no_pr'], 
                'purchase_product_name' => $key['data']['purchase_product_name'],
                'package' => $key['data']['package'],
                'unit' => $key['data']['unit'],
                'qty_approve' => $key['data']['qty_approve'],
                'purchase_id_tr' => $key['data']['purchase_id_tr'],
                'qty_hasil' => $key['data']['qty_hasil'],
                'unit_price' => $key['data']['unit_price'],
                'total_price' => $key['data']['total_price'],
                'warehouse_name' => $key['data']['warehouse_name']
            );

            $_updateDetailPO = array(
                'qty_order' => $key['data']['qty_order'],
                'qty_hasil' => $key['data']['qty_hasil']
            );

            if($key['type'] == 'U'){
                $where = array("purchase_id_tr = " . $this->_db->quote($key['data']['purchase_id_tr']));
                $table_detail_pr->update($_updateDetailPO,$where);
                $this->result->success = true;
            }

            if(!empty($key['data']['id'])){
                $where = array("id = " . $this->_db->quote($key['data']['id']));
                $table_detail->update($_insertDetail,$where);
                $this->result->success = true;
            }else{
                $_insertDetail['id_po'] = $header_id;
                $table_detail->insert($_insertDetail);
                $this->_db->commit();
                $updateStock = $this->updatePR($key['data']);
                $this->result->success = true;
            }

            if($key['type'] == 'D'){
                $where = array("id = " . $this->_db->quote($key['data']['id']));
                $table_detail->delete($where);
                $this->_db->commit();
                $this->result->success = true;
            }


        }
        return $_newdata;

    }


    }
    catch(Exception $_e) {
        $this->result->messages[] = new Sasmita_Transaction_Message('E', $_e->getMessage(), __CLASS__ . '/' . __FUNCTION__, __LINE__); 
    }
}

public function updatePR($data)
{
    //var_dump($data);
    //exit;
    $_sStock = $this->_db->select('a vending_tr_purchase_product','*')
    ->where('a.purchase_id_tr = ?',$data['purchase_id_tr'])
    //->where('a.warehouse_id = ?',$data['warehouse'])
    ->fetch();

    $table = new Zend_Db_Table('vending_tr_purchase_product');

    if(is_array($_sStock)){
        $pengurangan = $data['qty_hasil']-$data['qty_order'];
        $_updateDetailPO_R = array(
                'qty_order' => $data['qty_order'],
                'qty_hasil' => $pengurangan
            );
        $where = array("purchase_id_tr = " . $this->_db->quote($data['purchase_id_tr']));
        $a = $table->update($_updateDetailPO_R,$where);
        $this->result->success = true;
        //print_r ($a);
        //print_r($a->__toString());

    }else{
        $this->_db->beginTransaction();
        $_insertArray = array(
                'purchase_product_id' => $data['product_id'],
                'brand' => $data['data']['brand'],
                'package' => $data['data']['package'],
                'purchase_product_name' => $data['data']['product_name'],
                'qty_request' => $data['qty_request'],
                'qty_approve' => $data['qty_approve'],
                'qty_order' => $data['qty_approve'],
                'qty_hasil' => $data['qty_approve'],
                'approvel' => $data['approvel'],
                'unit_price' => $data['unit_price'],
                'unit' => $data['unit']
            );
        $table->insert($_insertArray);
        $this->_db->commit();
        $this->result->success = true;
    }

    return $this->result->success;
}
InputPO.js

requires: [
    'Ext.form.Panel',
    'Ext.form.FieldContainer',
    'Ext.form.field.Date',
    'Ext.form.field.File',
    'Ext.form.field.Hidden',
    'Ext.grid.Panel',
    'Ext.toolbar.Toolbar',
    'Ext.button.Button',
    'Ext.toolbar.Separator',
    'Ext.selection.CheckboxModel',
    'Ext.form.field.Number',
    'Ext.grid.column.Number',
    'Ext.grid.column.Date',
    'Ext.grid.column.Boolean',
    'Ext.grid.View',
    'Ext.grid.plugin.RowEditing',
    'Ext.grid.feature.Summary'
],

fileUpload: true,
height: 473,
width: 633,
title: '',

initComponent: function() {
    var me = this;

    Ext.applyIf(me, {
        items: [
            {
                xtype: 'form',
                bodyPadding: 10,
                title: '',
                items: [
                    {
                        xtype: 'fieldcontainer',
                        fieldLabel: '',
                        layout: {
                            type: 'hbox',
                            align: 'stretch'
                        },
                        items: [
                            {
                                xtype: 'container',
                                items: [
                                    {
                                        xtype: 'textfield',
                                        width: 250,
                                        fieldLabel: 'No. PO',
                                        labelWidth: 70,
                                        name: 'no_po'
                                    },
                                    {
                                        xtype: 'textfield',
                                        hidden: true,
                                        width: 250,
                                        fieldLabel: 'ID. PO',
                                        labelWidth: 70,
                                        name: 'id_po'
                                    },
                                    {
                                        xtype: 'datefield',
                                        width: 250,
                                        fieldLabel: 'Date',
                                        labelWidth: 70,
                                        name: 'date_po'
                                    },
                                    {
                                        xtype: 'textfield',
                                        width: 250,
                                        fieldLabel: 'Supplier',
                                        labelWidth: 70,
                                        name: 'supplier'
                                    }
                                ]
                            },
                            {
                                xtype: 'container',
                                margin: '0 0 0 10',
                                items: [
                                    {
                                        xtype: 'textfield',
                                        width: 250,
                                        fieldLabel: 'Total Price',
                                        labelWidth: 70,
                                        name: 'total_price_head'
                                    },
                                    {
                                        xtype: 'textfield',
                                        width: 250,
                                        fieldLabel: 'VAT',
                                        labelWidth: 70,
                                        name: 'vat'
                                    },
                                    {
                                        xtype: 'textfield',
                                        width: 250,
                                        fieldLabel: 'Net Price',
                                        labelWidth: 70,
                                        name: 'net_price'
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        xtype: 'container',
                        items: [
                            {
                                xtype: 'textfield',
                                hidden: true,
                                width: 511,
                                fieldLabel: 'Shipping To',
                                labelWidth: 70,
                                name: 'shipping_to'
                            },
                            {
                                xtype: 'filefield',
                                width: 511,
                                fieldLabel: 'Attachment',
                                labelWidth: 70,
                                name: 'file_path'
                            }
                        ]
                    },
                    {
                        xtype: 'hiddenfield',
                        name: 'action'
                    }
                ]
            },
            {
                xtype: 'gridpanel',
                height: 250,
                itemId: 'detailProduct',
                autoScroll: true,
                bodyBorder: false,
                title: 'Detail Product',
                store: 'vending.purchase.DetailProduct',
                dockedItems: [
                    {
                        xtype: 'toolbar',
                        dock: 'top',
                        items: [
                            {
                                xtype: 'button',
                                itemId: 'addDM',
                                iconCls: 'icon-add',
                                text: 'Add'
                            },
                            {
                                xtype: 'tbseparator'
                            },
                            {
                                xtype: 'button',
                                itemId: 'btnDelete_detailp',
                                iconCls: 'icon-delete',
                                text: 'Delete'
                            }
                        ]
                    }
                ],
                selModel: Ext.create('Ext.selection.CheckboxModel', {

                }),
                columns: [
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'purchase_id_tr',
                        text: 'Id'
                    },
                    {
                        xtype: 'gridcolumn',
                        hidden: true,
                        dataIndex: 'id_po',
                        text: 'Id'
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'warehouse_name',
                        text: 'Warehouse'
                    },
                    {
                        xtype: 'gridcolumn',
                        hidden: true,
                        dataIndex: 'qty_hasil',
                        text: 'Id'
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'no_pr',
                        text: 'No. PR'
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'purchase_product_name',
                        text: 'Product Name'
                    },
                    {
                        xtype: 'gridcolumn',
                        hidden: true,
                        dataIndex: 'string',
                        text: 'Brand'
                    },
                    {
                        xtype: 'gridcolumn',
                        hidden: true,
                        dataIndex: 'package',
                        text: 'Package'
                    },
                    {
                        xtype: 'gridcolumn',
                        hidden: true,
                        dataIndex: 'qty_approve',
                        text: 'Quantity Remaining'
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'unit',
                        text: 'Unit Order'
                    },
                    {
                        xtype: 'gridcolumn',
                        hidden: true,
                        dataIndex: 'qty_hasil',
                        text: 'Quantity Remaining'
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'qty_order',
                        text: 'Quantity',
                        editor: {
                            xtype: 'numberfield'
                        }
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'unit_price',
                        text: 'Unit Price',
                        editor: {
                            xtype: 'numberfield',
                            name: 'unit_price'
                        }
                    },
                    {
                        xtype: 'gridcolumn',
                        summaryType: 'sum',
                        dataIndex: 'total_price',
                        text: 'Total Price',
                        editor: {
                            xtype: 'numberfield',
                            name: 'total_price'
                        }
                    },
                    {
                        xtype: 'numbercolumn',
                        hidden: true,
                        dataIndex: 'number',
                        text: ''
                    },
                    {
                        xtype: 'datecolumn',
                        hidden: true,
                        dataIndex: 'date',
                        text: 'Date'
                    },
                    {
                        xtype: 'booleancolumn',
                        hidden: true,
                        dataIndex: 'bool',
                        text: 'Boolean'
                    }
                ],
                plugins: [
                    Ext.create('Ext.grid.plugin.RowEditing', {
                        clicksToEdit: 1
                    })
                ],
                features: [
                    {
                        ftype: 'summary'
                    }
                ]
            },
            {
                xtype: 'gridpanel',
                hidden: true,
                title: 'Lokasi Pengiriman',
                columns: [
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'string',
                        text: 'Nama gudang'
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'string',
                        text: 'Alamat'
                    },
                    {
                        xtype: 'gridcolumn',
                        dataIndex: 'string',
                        text: 'Shipping To'
                    },
                    {
                        xtype: 'numbercolumn',
                        hidden: true,
                        dataIndex: 'number',
                        text: 'Number'
                    },
                    {
                        xtype: 'datecolumn',
                        hidden: true,
                        dataIndex: 'date',
                        text: 'Date'
                    },
                    {
                        xtype: 'booleancolumn',
                        hidden: true,
                        dataIndex: 'bool',
                        text: 'Boolean'
                    }
                ]
            }
        ]
    });

    me.callParent(arguments);
}

});
这是我的控制器js动作点击按钮保存:

onButtonSave: function(button, e, eOpts) {

console.log("suksesss");
var me = this;
var _panel = me.getMainPanel();
var _tabpanel = _panel.down("#tabmaintain");
var _activetab = _tabpanel.getActiveTab();
var form = _activetab.down('form').getForm();
var values = form.getValues();
var myMask = new Ext.LoadMask(_activetab, {msg:"Please wait..."});


if(form.isValid())
{
    myMask.show();
    form.submit({
        url: '/jsonresult/Sasmita_Vending_Purchase/saveGoodsReceived',
        success: function(fp, o) {
            myMask.hide();
            //me.fnReloadTabAttachment();
            _activetab.close();
        },
        failure: function(fp,o){
            myMask.hide();
            if(!o.result.session)
            {
                Ext.Msg.alert('Error', o.result.messages);
            }
            else
            {
                if (o.result.messages[0].text)
                {
                    Ext.Msg.alert('Error', o.result.messages[0].text);
                }
                else
                {
                    Ext.Msg.alert('Error', o.result.messages);
                }
            }
        }
    });
}
},
这里说的是foreach时的错误

您正在尝试解码无效的JSON字符串:

其次是:

警告:第331行Purchase.php中为foreach()提供的参数无效↵ {“success”:false,“data”:{“no_-po”:null,“date_-po”:null,“supplier”:null,“shipping_-to”:null,“total_-price”:null,“id_-po”:null,“file_-ext”:“png”,“file_-type”:“image/png”,“file_-size”:633237,“file_-name”:“2015-02-23-Negative-World-left-hand.png”},“messages”:[],“pageSize”:null,“start”:null,“start”:null,“total”:null,“session”:true,“other”:null,“processingTime”:null}

这可能意味着您的代码希望在警告之后解析JSON,但却同时得到了这两个JSON。这将导致组合的无效JSON字符串

解决方案是在触发前检查您所覆盖的集合
foreach
是否为集合(例如数组):

if(is_array($_detail)) {
    foreach ($_detail as $key) {
        // ...
    }
} else {
    // Do something else
}

Hi@Dymen1,我完成了,解决方案是检查集合是否为每个,现在没有错误或输出任何内容,当我检查我的数据库时,没有要保存到我的数据库的内容(没有添加新记录)…您需要检查dB提交的结果(通过检查事务状态的函数或通过提交调用的返回)