Welcome Guest, Not a member yet? Register   Sign In
The getRandomName() function return wrong file Extension
#1

(This post was last modified: 09-23-2023, 06:29 AM by murugappan.)

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.
Reply
#2

What do you get when you var_dump($imageFile) ?
Reply
#3

@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" }
Reply
#4

@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.
Reply
#5

Please edit your topic title and add [SOLVED] to the end of it
Thank you.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB