TFT2012 Posted October 1, 2014 Share Posted October 1, 2014 (edited) That's my first time to see this kind of issue. The PROD environment: Godaddy, IIS7, PHP5.4.30 The Local environment: Linux, PHP 5.5.X The framework: CodeIgniter 2.2.0 Process: I have view have form to update multiple files. echo form_open_multipart('admin/UploadFiles'); The controller will do an initial check, if( isset($_SERVER["CONTENT_LENGTH"]) && ($_SERVER["CONTENT_LENGTH"]>((int)ini_get('post_max_size')*1024*1024))) { $this->session->set_flashdata('upload_error', 'Your file is too big to handle.'); redirect($_SERVER['HTTP_REFERER']); } else { if($_FILES['files']['error'][0] != 0) { $this->session->set_flashdata('upload_error', 'There are no files selected.'); redirect($_SERVER['HTTP_REFERER']); } else { $photo_info = array(); $photo_info = $_FILES['files']; $this->load->model('uploadfile'); $results = $this->uploadfile->UploadImages($photo_info); // My debug echo "<pre>"; print_r($results); echo "</pre>"; // redirect($_SERVER['HTTP_REFERER']); } In my model file, for debug purpose, I only put these lines. Since I have traced the code line one by one, finally found the 500 error happens here. if (!empty($this->CheckFileError($images))) { $results['fail'] = $this->CheckFileError($images); foreach($this->CheckFileError($images) as $err) $error_idx[] = $err['index']; } It happens on empty($this->CheckFileError($images)) //$this->CheckFileError($images) is an array If I just "return $this->CheckFileError($images)", it has no error at all. But If I do the code above, it will give me Internal 500 error. After I change to count($this->CheckFileError($images)) == 0 everthing works. All the other logics in the actual model are remain same. I only change this line. It has no problem at all in my local. Only when I run it on my Godaddy IIS share hosting. Initially I thought the temp folder to hold the files is not writable. I even spent whole night to talk to Godaddy guys, but no progress. Even I tried create .user.ini to change the "upload_tmp_dir", it still gave me 500 error. Tonight, I debugged my code lines one by one, tested it in local first, then tested in Godaddy. Finally I found the root cause for my internal 500 error. However, I don't know why empty() will cause this issue. Can anyone explain it? I Googled, but didn't find any userful information. The reason why I use IIS is because I write my most of the services in WCF. Thanks! Edited October 1, 2014 by TFT2012 Quote Link to comment https://forums.phpfreaks.com/topic/291379-the-internal-500-error-caused-by-empty/ Share on other sites More sharing options...
requinix Posted October 1, 2014 Share Posted October 1, 2014 empty() only works on expressions, such as function calls, as of PHP 5.5. Guess you're using 5.4 or 5.3 (hopefully nothing earlier than that). The easiest solution is simply to not use empty() in those situations. You should also make sure the PHP version you're using to develop and test with is the same version as is actually on your live site. To avoid this kind of problem in the future. Quote Link to comment https://forums.phpfreaks.com/topic/291379-the-internal-500-error-caused-by-empty/#findComment-1492481 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.