I am trying to upload image using zend form class and my current input filter is this
$inputFilter->add([
"name" => "ImageLogo",
"required" => false,
"validators" => [
[
"name" => "FileMimeType",
"options" => [
"mimeType" => [ "image/jpeg", "image/png" ],
],
],
[
"name" => "FileIsImage",
],
],
"filters" => [
[
"name" => "FileRenameUpload",
"options" => [
"target" => getcwd() . "/public/uploads/logos",
"useUploadName" => true,
"useUploadExtension" => true,
"overwrite" => true,
"randomize" => true,
],
],
],
]);
It uploads perfectly, but I have some parts that I couldn't able to modify.
First, I would like $entity's Id to be prepended before uploading. Something like, $entity->getId() . $fileName (Confusion: what if I'm adding a new entity. There won't be id)
Second, how would I get file name in controller after validating form. This
if ($form->isValid()) {
print_r($form->getData());exit();
}
Shows old name.
I have a similar application. Here is how I did it if it helps.
I create the record in db with the tmp_name.
Now I have the entity id and the file name. I don't change the file name in DB (the app is happy with the server random name) but from here all the informations are available if you need.