首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CodeIgniter文件上传黑洞

CodeIgniter文件上传黑洞
EN

Stack Overflow用户
提问于 2012-05-09 01:32:40
回答 1查看 667关注 0票数 0

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

控制器:

代码语言:javascript
复制
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
    }
}

查看:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-12 01:04:04

我使用xDebug profiler发现了这个bug。原来问题出在下游的原生php函数chdir(path)上。@qwertzman指向paths in CI的链接可能有助于确定发生挂起的确切原因。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10503537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档