dirk
November 30, 2021, 6:24pm
1
I try to check if file upload was successfull.
At the moment I use
if (empty($uploaded_file->moveTo($destination.$fileName))) {...}
Can anyone tell if this is the right way to check this, or show me a link where I can find further information?
regards
dirk
moveTo()
doesn’t have a return value.
See laminas-diactoros/UploadedFile.php at 2.9.x · laminas/laminas-diactoros · GitHub
You will need to surround that function with a try-catch block and catch exceptions accordingly to do what you want to do if it fails.
dirk:
$destination.$fileName
it may not be as elegant as a try/catch - but maybe sufficient enough - to do a
if(is_file($destination.$fileName)) { ... }
after your move.
Zuluru
December 7, 2021, 10:21pm
7
if it’s throwing an exception, an if
statement doesn’t seem like it’s going to be useful.
ADmad
December 8, 2021, 1:37pm
8
UploadedFileInterface::moveTo()
doesn’t have a return value. The operation will either be successful or throw an exception. So you need to use a try
/ catch
block if you want to handle the failure.