Per default the move function of CodeIgniter 4 returns true
if a file has moved.
But if a file already exists, it adds a delimiter with a counter to the filename and as I am having only true
I don't have the new filename, that I want to store in the database.
I could extend the UploadedFile
class (what is honestly very hard for me), but I am asking as I feel, wanting to know the filename is much intuitive, so that there most be an easier approach.
CodePudding user response:
A tiny correction: not move function
.
It should be move method
for File
instance.
Based on which name you want to get, there are three available methods:
getName()
You can retrieve the original filename provided by the client with the getName() method. This will typically be the filename sent by the client, and should not be trusted. If the file has been moved, this will return the final name of the moved file:
$name = $file->getName();
getClientName()
Always returns the original name of the uploaded file as sent by the client, even if the file has been moved:
$originalName = $file->getClientName();
getTempName()
To get the full path of the temp file that was created during the upload, you can use the getTempName() method:
$tempfile = $file->getTempName();
Check the CI4 Documentation for more information.