2016-11-21 122 views
0

我想使用CodeIgniter上传文件。这台服务器似乎有一些奇怪的事情发生,因为代码在其他服务器上工作正常。我试图调试这个问题,但没有错误报告。CodeIgniter上传失败没有错误日志没有错误报告

具体而言,代码:

if (!$this->upload->do_upload()) { 
    var_dump($this->upload->display_errors()); 
    exit(); 
} 

我已经接通和的display_errors使用error_reporting(E_ALL),没有被示出。只是一个空白页面。我知道这些设置的工作原理,因为如果我犯了一个语法错误,错误将显示。当我上传文件时,这只是一个完整的空白页面。它是100%确定上传文件。

我甚至已经打开笨日志,错误报告级别设置为4,但没有日志文件被所有写入。我已将其设置为默认日志文件。

最后,我检查phpinfo()函数设置file_uploads和一切似乎都不错。他们已经开启,没有疯狂的上传限制或类似的东西。

我可以创建文件的fopen()和它的文件写入到服务器的罚款。

关于我能做些什么来尝试和调试的想法?我没有服务器访问权限(这是为客户端),所以我试图依靠使用SFTP和错误输出。但我什么都没有。

我设法让日志文件输出这样的:

INFO - 2016-11-28 01:24:07 --> Session: Class initialized using 'files' driver. 
INFO - 2016-11-28 01:24:07 --> Model Class Initialized 
INFO - 2016-11-28 01:24:07 --> Controller Class Initialized 
INFO - 2016-11-28 01:24:07 --> Model Class Initialized 
INFO - 2016-11-28 01:24:07 --> Model Class Initialized 
INFO - 2016-11-28 01:24:07 --> Helper loaded: email_helper 
INFO - 2016-11-28 01:24:07 --> Upload Class Initialized 

如此看来脚本停止在上传类进行初始化的一部分。

+0

什么'$这个 - > upload-> do_upload()'返回? –

+0

它不会返回任何东西。我试过:var_dump($ this-> upload-> do_upload()); \t \t \t出口(); – Patchesoft

+2

你可以复制粘贴你的表格,它的属性在这里?还要确保上传一个你正在获取'$ _FILES'文件的文件。先检查一下。 –

回答

2

鉴于this comment

Its CodeIgniter 3.1.2 (latest) and they are running PHP 5.4. Error_reporting and display_errors was enabled by the host, in the ini settings I assume. Their host is Dreamhost.

我可以99%肯定地说,你没有启用Fileinfo extension,并因此受到"bug" #4887 in CodeIgniter

的Fileinfo的扩展被描述为"enabled by default as of PHP 5.3.0" on php.net,这就是为什么一个function_exists('finfo_file')支票从CI_Upload 3.1.1版本中删除。但事实证明,一些发行和/或托管服务提供商明确禁用扩展,显然你是由影响,导致出现以下错误:

PHP Fatal error: Call to undefined function finfo_file() in /path/to/system/libraries/Upload.php on line 1225

你看不到的错误,因为你没有实际使display_errors为笨的应用程序,可能没有在日志中寻找它...
框架本身将总是默认启用error_reporting,并禁用display_errors如果您将ENVIRONMENT以“测试”或“生产'在其index.php文件 - 我猜你已经设置为'生产'。因此,在php.ini中启用这些设置都没关系,因为CodeIgniter会覆盖它们。

该问题影响CodeIgniter版本3.1.1和3.1.2。 3.1.3之前解决它出来,你可以启用Fileinfo的扩展或应用这个补丁:https://github.com/bcit-ci/CodeIgniter/commit/7cc08237c2a15daf283e2bc61501bdc086740311

+0

谢谢!这是正确的,并解决了这个问题:) – Patchesoft