dtx9763
2012-05-16 13:09
采纳率: 100%
浏览 65
已采纳

使用php和ExtJs无法正常上传文件

I need the simplest solution for uploading file from Ext application with php. I'm a total php newbie, so I don't get the errors I'm recieving and can only guess what's causing them. On the frontend side I have a simple form :

Ext.create('Ext.form.Panel', {
    width: 300,
    renderTo: Ext.getBody(),
    frame: false,
    title: 'File Upload Form',
    bodyPadding: '10 10 0',

    defaults: {
        anchor: '100%',
        allowBlank: false,
        msgTarget: 'side',
        labelWidth: 50
    },

    items: [{
        xtype: 'filefield',
        id: 'form-file',
        emptyText: 'Select mpp file',
        fieldLabel: 'File',
        name: 'mpp-file',
        buttonText: '',
        buttonConfig: {
            iconCls: 'upload-icon'
        }
    }],
    buttons: [{
        text: 'Upload',
        handler: function(){
            var form = this.up('form').getForm();
            if(form.isValid()){
                form.submit({
                    url: 'msp-load.php',
                    waitMsg: 'Loading data...',
                    success: function(fp, o) {
                        msg('Success', 'Data from .mpp file loaded ');
                    }
                });
            }
        }
    }]
})

The msp-upload.php looks as follows :

<?
if(isset($_FILES)){
    $file_tmp  = $_FILES['mpp-file']['tmp_name'];
    $file_name = $_FILES['mpp-file']['name'];
    $file_size = $_FILES['mpp-file']['size'];

    //echo ($file_tmp.", ".$file_name.", ".$file_size);

    if(is_uploaded_file($file_tmp)) {
        if(move_uploaded_file($file_tmp, "tmp/$file_name")){
            echo '{success: true}';
        } else {
            echo '{success: false}';
        }    
    }  else{
        echo '{success: false}';
    }
}
?>

After clicking 'Upload' I get :

uncaught exception: Ext.JSON.decode(): You're trying to decode an invalid JSON String: <br> <b>Warning</b>: move_uploaded_file(tmp/MSP1.mpp) [<a href="function.move-uploaded-file">function.move-uploaded-file</a>]: failed to open stream: No such file or directory in <b>/Library/WebServer/Documents/examples/MSProject_import/msp-load.php</b> on line <b>10</b><br> <br> <b>Warning</b>: move_uploaded_file() [<a href="function.move-uploaded-file">function.move-uploaded-file</a>]: Unable to move '/private/var/tmp/phpJVDktB' to 'tmp/MSP1.mpp' in <b>/Library/WebServer/Documents/examples/MSProject_import/msp-load.php</b> on line <b>10</b><br> {success: false}

Where does this : 'No such file...' error come from? It can't find the uploaded file, or something else? My server user has admin privileges so it's not about permissions.

I'm using built-in OSX 10.7 server with PHP 5.3.6 . No errors in the error.log .

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongxin8709 2012-05-16 13:28
    已采纳

    As mentioned above there are two possible problems.

    1. Path Error(basically path which you are giving to upload is not valid)
    2. Or the wrong permission are given. (CHMOD 777)
    已采纳该答案
    打赏 评论
  • dragon87836215 2012-05-16 13:13

    You have error message from your msp-upload.php : Unable to move '/private/var/tmp/phpJVDktB' to 'tmp/MSP1.mpp' You have to set full destination path with write access

        if(move_uploaded_file($file_tmp, dirname(__FILE__)."/tmp/$file_name")){
            echo '{success: true}';
        } else {
            echo '{success: false}';
        } 
    
    打赏 评论

相关推荐 更多相似问题