【发布时间】:2012-05-10 21:02:13
【问题描述】:
我正在 CodeIgniter 2.0.2 中编写一个简单的文件上传器。下面粘贴代码。 在某些条件下,浏览器在此上传期间挂起,我在浏览器状态栏中看到“等待本地主机”(FF 和 Chrome 中的行为相同)。 我已经验证该文件正在上传到 Windows 临时文件夹(完整文件),但之后该过程卡住了。 似乎该错误的条件是文件大小。但是我的 php.ini 具有上传文件的所有正确设置,而且我仍然可以使用 700k 文件。 仅当我在 Windows 7 Apache 上运行它时才会出现此错误,而不是在 Ubuntu 机器上运行。 向我建议 php.ini 中的某些路径可能设置不正确。 Apache 日志文件在这里没有太大帮助,因为没有抛出错误。 我曾尝试使用 Chrome 开发者面板进行调试,但没有发现任何有用的东西。 我目前正在尝试让 XDebug 工作,但由于没有引发错误并且该过程没有完成,我的期望很低。 有关如何跟踪此错误的任何建议? 如果您想查看特定的 php.ini 设置,请告诉我,不要做大转储。
控制器:
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);
if ( ! $this->upload->do_upload()) // this is the native CI function, probably where the problem is. I can provide some of that code if anyone wants.
{
$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>
【问题讨论】:
-
可能是
$this->restore_backup($file_upload)挂了?尝试评论这一行,看看会发生什么。 -
只是为了记录,xdebug 确实会在脚本运行时写入分析数据,因此即使脚本本身永远不会结束,您也可以查看一些内容。
-
好的,我已经进行了 xdebug 分析,并将结果加载到 winCacheGrind 中。现在解释分析...
-
附带说明,为了调试这个脚本,你必须使用 PHP 调试器,因为这是服务器端代码,所以像 Chrome 网页调试器这样的东西不能用于这个 --您必须使用某种 IDE(如 Eclipse PHP IDE 或其他东西)来执行脚本,以便在运行时操作期间调试脚本。您的另一个选项是打开 PHP 错误报告(不要忘记在生产时将其关闭!),只需在要调试的脚本中包含这两个命令:
ini_set('display_errors',1); error_reporting(E_ALL);这将允许 PHP 打印任何错误到屏幕。
标签: codeigniter file-upload php