CodeIgniter Forums
File upload work on php 7.2, but not on 7.4.14 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: File upload work on php 7.2, but not on 7.4.14 (/showthread.php?tid=78441)



File upload work on php 7.2, but not on 7.4.14 - t_5810 - 01-20-2021

I have an Codeigniter app, which works like a charm on PHP 7.2
After moving on PHP 7.4.14, I get an error "No input file specified." Search on Google suggested that I should add a question mark in my .htaccess file
Code:
RewriteRule ^([\s\S]*)$ index.php?/$1 [L,NC,QSA]
to resolve the issue. And that was the only change that I did. However, I notice that since the upgrade, my code for uploading images does not work (application wide).
I have options to upload images on many pages, and they all works if I switch back to PHP 7.2, but does not work on PHP 7.4.14
The error that I get is:
finfo_file(): Empty filename or path
My validation code is the following:


Code:
// Thumbnail image is not required, so validation is optional
$webpageThumbnailImage = $this->request->getFile('webpageThumbnailImage');
    if ($webpageThumbnailImage != "") {
        if (!($this->validate([
            'webpageThumbnailImage'            => [
            'uploaded[webpageThumbnailImage]',
            'mime_in[webpageThumbnailImage,image/jpg,image/jpeg,image/gif,image/png,image/bmp]',
                        'max_size[webpageThumbnailImage,4096]',
            ],
        ]))) {
        // Validation has failed, redirect the user back
        return redirect()->to(base_url() . '/Backend/Webpage/edit_record/' . $this->request->getPost('webpageID'))->withInput();
    }
    if (!$webpageThumbnailImage->isValid()) {
        throw new RuntimeException($webpageThumbnailImage->getErrorString() . '(' . $webpageThumbnailImage->getError() . ')');
    }
    $newName = $webpageThumbnailImage->getRandomName();
    $webpageThumbnailImage->move('./backOffice/backOfficeImages/', $newName);
} else {
    $newName = NULL;
}

Questions is: Why this code works on PHP 7.2 and does not work on PHP 7.4.14?


RE: File upload work on php 7.2, but not on 7.4.14 - InsiteFX - 01-20-2021

Well it can be anything, also you did not specify what version of CodeIgniter you are running.

Read the change logs.

PHP 7 ChangeLog


RE: File upload work on php 7.2, but not on 7.4.14 - t_5810 - 01-20-2021

Thanks for your reply, and for spending your time to help me.

(01-20-2021, 04:10 AM)InsiteFX Wrote: Well it can be anything, also you did not specify what version of CodeIgniter you are running.

Read the change logs.

PHP 7 ChangeLog

My bad. Thanks for pointing that to me. CodeIgniter version is: 4.04 CI

As far for the log error, here it is:

Code:
CRITICAL - 2021-01-20 11:46:12 --> finfo_file(): Empty filename or path
#0 [internal function]: CodeIgniter\Debug\Exceptions->errorHandler(2, 'finfo_file(): E...', 'D:\\Sites\\ea3\\sy...', 153, Array)
#1 D:\Sites\ea3\system\Files\File.php(153): finfo_file(Resource id #129, '')
#2 D:\Sites\ea3\system\Validation\FileRules.php(251): CodeIgniter\Files\File->getMimeType()
#3 D:\Sites\ea3\system\Validation\Validation.php(325): CodeIgniter\Validation\FileRules->mime_in(NULL, Array, Array, NULL)
#4 D:\Sites\ea3\system\Validation\Validation.php(189): CodeIgniter\Validation\Validation->processRules('webpageThumbnai...', 'webpageThumbnai...', NULL, Array, Array)
#5 D:\Sites\ea3\system\Controller.php(219): CodeIgniter\Validation\Validation->run()
#6 D:\Sites\ea3\app\Controllers\Backend\Webpage.php(190): CodeIgniter\Controller->validate(Array)
#7 D:\Sites\ea3\system\CodeIgniter.php(918): App\Controllers\Backend\Webpage->edit_record()
#8 D:\Sites\ea3\system\CodeIgniter.php(404): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Backend\Webpage))
#9 D:\Sites\ea3\system\CodeIgniter.php(312): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
#10 D:\Sites\ea3\public\index.php(45): CodeIgniter\CodeIgniter->run()
#11 {main}



RE: File upload work on php 7.2, but not on 7.4.14 - InsiteFX - 01-20-2021

If you look at the 7.4.14 change log I believe they fixed a bug for the finfo_file().

This maybe a new bug in CI not sure but you can report it to the developmen5t team on GitHub