0

我正在尝试以正常方式在 CodeIgniter 2.0.2 中上传单个文件。该do_upload()函数返回true,但目录中没有文件出现。目录权限似乎没问题(在运行下面代码中未显示的其他诊断之后),因此文件没有出现在上传目录中是没有意义的。这是控制器和视图代码,直接改编自 CI 文档。

控制器:

function do_upload_sql(){
    // create directory
    if (! is_dir(BACKUP_DIR)) {
        mkdir(BACKUP_DIR, 0777);
    }
    // or if it exists and has restricted file permissions, change them
    elseif(fileperms(BACKUP_DIR)!=0777){
        chmod(BACKUP_DIR, 0777);
    }

    $config['upload_path'] = BACKUP_DIR;
    $config['allowed_types'] = 'backup'; // an SQL backup file type
    $config['overwrite'] = TRUE;
    $this->load->library('upload', $config);
    //$this->upload->initialize($config);  //redundant, so commenting out
    if ( ! $this->upload->do_upload())
    {
        $data['action'] = 'c_backup_restore/do_upload_sql';
        $tab_error = array('error' => $this->upload->display_errors());
        $data['error'] = $tab_error['error'];
        $this->load->view('common/header');
        $this->load->view('v_upload_sql', $data);
    }
    else
    {
        echo "success"; // yes it's getting here, but i get no file!
        $data = array('upload_data' => $this->upload->data());
        $file_upload = $data["upload_data"];
        $this->restore_backup($file_upload); // go do something useful with the file
    }
}

看法:

<p>Select the backup file</p>
<div class="not_success"><?php echo $error;?></div>
<?php echo form_open_multipart($action);?>
<input type="file" name="userfile" size="30" />
<input type="submit" value="Upload" />
</form>
4

1 回答 1

0

我使用xDebug profiler发现了这个错误。事实证明,chdir(path)更下游的原生 php 函数是问题所在。@qwertzman 指向CI 中路径的链接可能有助于确定发生挂断的确切原因。

于 2012-05-11T17:04:04.030 回答