CodeIgniter Forums
The getRandomName() function return wrong file Extension - 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: The getRandomName() function return wrong file Extension (/showthread.php?tid=88536)



The getRandomName() function return wrong file Extension - murugappan - 09-23-2023

Hi,

I am using CI 4 Version 4.4.1 and using Postman to post data using the apps API. In the HTTP Request i am uploading a file which ends in .png extension. The problem i get is with the getRandomName() function which is returning a file extension .bin instead.
This is my code:
PHP Code:
$imageFile $this->request->getFile('profile_image');
 
$newImageNamex $imageFile->getRandomName(); 
The value returned is (using Kint Dump):
Code:
$newImageNamex string (35) "1695474962_f067be8c9efe341ed38b.bin"


Is there a bug or there something missing in the code? I could not find help in CI4 documentation.



RE: The getRandomName() function return wrong file Extension - sammyskills - 09-23-2023

What do you get when you var_dump($imageFile) ?


RE: The getRandomName() function return wrong file Extension - murugappan - 09-23-2023

@sammyskills  this is what i get when i do a var_dump($imageFile) :

Code:
object(CodeIgniter\HTTP\Files\UploadedFile)#78 (10) { ["size":protected]=> int(47156) ["originalMimeType":protected]=> string(9) "image/png" ["path":protected]=> string(24) "C:\xampp\tmp\php3B74.tmp" ["clientPath":protected]=> string(14) "banner-img.png" ["originalName":protected]=> string(14) "banner-img.png" ["name":protected]=> string(14) "banner-img.png" ["error":protected]=> int(0) ["hasMoved":protected]=> bool(false) ["pathName":"SplFileInfo":private]=> string(24) "C:\xampp\tmp\php3B74.tmp" ["fileName":"SplFileInfo":private]=> string(11) "php3B74.tmp" }



RE: The getRandomName() function return wrong file Extension - murugappan - 09-23-2023

@sammyskills
I resolved the problem. The problem was not the code but the uploaded file using RapidAPI Client extension in vs code.

Thank your for the help.


RE: The getRandomName() function return wrong file Extension - InsiteFX - 09-23-2023

Please edit your topic title and add [SOLVED] to the end of it
Thank you.