Closed radmax closed 7 years ago
Hi @radmax , here (https://github.com/Gargron/fileupload/blob/master/src/FileUpload/FileUpload.php#L362), i think the undefined behaviour is as a result of the $file_path
variable that does not exist if the validation fails. Am i right ? would like more info on this issue though.
Another thing is i do not like the fact that an Exception
is introduced since it is kind of different from the default behaviour - which is to still return a File
object that has it's completed
property as false.
Could you try moving $file_path
(https://github.com/Gargron/fileupload/blob/master/src/FileUpload/FileUpload.php#L316) to maybe 5 lines above and see if this undefined behaviour still exists.
Ok, i agree that just throwing naked Exception
is not best solution.
I think problem is bigger than just undefined variable. If i move statement in front of validation condition, then next point of failure is File.php constructor calling method setMimeType
. Filename passed is path of file for final destination directory. If validation had passed it would be copied there, but that file doesnt exist.
Oh that's true.. The constructor would "error out"..
So an exception seems the only way to go ? Do you have any other idea as to how to handle this. ?
Currently not with my laptop
If not, I'd merge #38 later
I tried #38 only as hotfix. Throwing exception should be implemented in better way (include specific message what failed or even custom exception class). I don't think my PR should be merged as it is right now. My intention was to start discussion and provide starting solution for this problem.
Thanks a lot.. I would look into this tomorrow and try to find a balanced ground
HI @radmax, I tried something on the hot-fix branch that doesn't involve an Exception
. Can you take a look at it and try that out if it solves your particular issue ?
Here is the commit https://github.com/Gargron/fileupload/commit/5595d8b8ecbf43bc0efab7423e26bece0b7f81d9 .
Ping @radmax
I tested it and it works. Thanks.
Thanks a lot, i should tag a release with this fix as soon as possible. #44 is holding me back
I just tagged a new release.. If there are issues, you can always reopen this issue.
BTW, thanks
In case of failed validation L362 of FileUpload.php has undefined state.
I patched it by adding
else
section and throwing exception, that i handle in my app. What should be proper behavior?