San*_*git 3 php image-uploading symfony
我想知道是否有人可以告诉我如何使用 formbulder 获取在 symfony 2.8 中上传的 i 文件的图像尺寸
图像实体有一个属性 $file
/*
* @Assert\Image(
* minWidth = 400,
* maxWidth = 1200,
* minHeight = 400,
* maxHeight = 1200
* )
*/
public $file;
Run Code Online (Sandbox Code Playgroud)
在控制器中,我构建了这样的表单
$form = $this->createFormBuilder($image)
->add('file', FileType::class)
->add('title', TextType::class)
Run Code Online (Sandbox Code Playgroud)
然后处理请求
$form->handleRequest($request);
if ($form->isSubmitted()) {
$file = $image->getFile();
if (!in_array($file->getClientMimeType(), self::$allowedMimeTypes)) {
throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $file->getClientMimeType()));
}
[...]
Run Code Online (Sandbox Code Playgroud)
我有两个二传手方法
$image->setSizeX($x);
$image->setSizeY($y);
Run Code Online (Sandbox Code Playgroud)
但是不能为了上帝的爱弄清楚如何从文件对象中获取 $x 和 $y 。
| 归档时间: |
|
| 查看次数: |
4268 次 |
| 最近记录: |