我正在尝试以正常方式在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>
答案 0 :(得分:0)
我使用xDebug profiler找到了错误。
事实证明,下游的本机php函数chdir(path)
是问题所在。
@ qwertzman的paths in CI链接可能有助于确定挂断的确切原因。