我正在尝试使用 zend 表单类上传图像,我当前的输入过滤器是这个
$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,
],
],
],
]);
它上传完美,但我有一些我无法修改的部分。
首先,我希望$entity
在上传之前添加 's Id。像,$entity->getId() . $fileName
(困惑:如果我要添加一个新实体怎么办。不会有 id)
其次,验证表单后如何在控制器中获取文件名。这个
if ($form->isValid()) {
print_r($form->getData());exit();
}
显示旧名称。