I managed to find the reason for my problem above.
In fact, the problem is not in this code, it is in the file that I am sending to the server and, for some reason, Laravel/PHP cannot retrieve important information to validate correctly, as follows:
In the correct scenario, where it worked as I expected, the server printout is:
(notice that Laravel managed to get the size and other values)
Illuminate\Http\UploadedFile {#1523 // app/Validators/OrderFileValidator.php:58
-test: false
-originalName: "2023-11-12 09-17-00.mp4"
-mimeType: "video/mp4"
-error: 0
#hashName: null
path: "/tmp"
filename: "phpsItJmi"
basename: "phpsItJmi"
pathname: "/tmp/phpsItJmi"
extension: ""
realPath: "/tmp/phpsItJmi"
aTime: 2024-02-12 10:33:26
mTime: 2024-02-12 10:33:26
cTime: 2024-02-12 10:33:26
inode: 3805560
size: 1906989
perms: 0100600
owner: 33
group: 33
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
}
Illuminate\Support\MessageBag {#1547
#messages: array:1 [
"attachment" => array:2 [
0 => "The maximum file size is 1 mb (megabyte)"
1 => "The extensions allowed for the file are: jpeg,png,jpg,gif,svg,pdf"
]
]
#format: ":message"
}
Now, for the invalid file (the reason for opening this question), Laravel/PHP read the following values:
(Note that it can't get the file size and several other attributes)
Illuminate\Http\UploadedFile {#1523 // app/Validators/OrderFileValidator.php:58
-test: false
-originalName: "Presentation - José Victor_20240125_070758_0000.pdf"
-mimeType: "application/octet-stream"
-error: 1
#hashName: null
path: ""
filename: ""
basename: ""
pathname: ""
extension: ""
realPath: "/var/www/html/app/public"
aTime: 1969-12-31 21:00:00
mTime: 1969-12-31 21:00:00
cTime: 1969-12-31 21:00:00
inode: false
size: false
perms: 00
owner: false
group: false
type: false
writable: false
readable: false
executable: false
file: false
dir: false
link: false
}
dd($_FILES);
array:1 [
"attachment" => array:5 [
"name" => "Presentation - José Victor_20240125_070758_0000.pdf"
"type" => ""
"tmp_name" => ""
"error" => 1
"size" => 0
]
]
Here is also the form I am using to send the file:
<form action="http://localhost:8080/app/public/..." method="POST" enctype="multipart/form-data">
<input type="file" class="form-control" name="attachment" required="">
...
</form>
My only question is: WHAT NOW? WHAT IS PHP'S CRITERIA FOR READING A FILE AND NOT READING ANOTHER?
Is there a PHP configuration file where I limit something like this?
"attachment.uploaded" => "file upload error"uploaded? @N69S . I dont want this error.lang/en/validator.phpyou will find all the messages for validator error and that specific message is returned inuploadederror.'uploaded' => 'The :attribute failed to upload.',