Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

php - CodeIgniter upload fail no error logs no error reporting

I am trying to upload a file using CodeIgniter. This server seems to have something strange going on because the code works fine on other servers. I'm trying to debug the issue but no errors are being reported.

To be specific, the code:

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

I have turned error_reporting(E_ALL) on and display_errors, nothing is shown. Just a blank page. I know these settings work because if I make a syntax error, the errors will show. It's just a complete blank page when I upload a file. It is 100% sure uploading a file.

I have even turned on the CodeIgniter log, error reporting level set to 4, but no log files are being written at all. I have set it to the default log file.

Finally, I checked the PHPinfo() settings for file_uploads and all seems okay. They are set to on, no crazy upload limit or anything like that.

I can create files with fopen() and it writes the file to the server fine.

Any ideas on what I can do to try and debug? I don't have server access (it's for a client) so I'm trying to rely on using SFTP and error output. But I'm getting nothing.

I managed to get the log file to output this:

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

So it seems the script stops at the Upload Class Initialized part.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Given 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.

I can say with 99% certainty that you don't have the Fileinfo extension enabled, and are thus affected by "bug" #4887 in CodeIgniter.

The Fileinfo extension is described as "enabled by default as of PHP 5.3.0" on php.net, which is why a function_exists('finfo_file') check was removed from CI_Upload in version 3.1.1. But it turned out some distributions and/or hosting providers explicitly disable the extension, and apparently you are affected by that, resulting in the following error:

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

You don't see the error because you didn't actually enable display_errors for the CodeIgniter application, and probably didn't look in the logs for it ...
The framework itself will always enable error_reporting by default, and disable display_errors if you set your ENVIRONMENT to 'testing' or 'production' in its index.php file - I'm guessing you have it set to 'production'. Hence, it doesn't matter that either of these settings are enabled in php.ini, because CodeIgniter will override them.

The issue affects CodeIgniter version 3.1.1 and 3.1.2. To resolve it before 3.1.3 comes out, you can either enable the Fileinfo extension or apply this patch: https://github.com/bcit-ci/CodeIgniter/commit/7cc08237c2a15daf283e2bc61501bdc086740311


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...