I am trying to upload an image into the path : {project}/public/img/circuits ,using vichuploaderBundle.
I followed his github documentation : https://github.com/dustin10/VichUploaderBundle/blob/master/docs/index.md
The situation is :
I have a form with a VichImageType
and when I submit said form with an image I get this :
thumbnailFile: SymfonyComponentHttpFoundationFileUploadedFile {#91 ▼
-test: false
-originalName: "meme.jpg"
-mimeType: "image/jpeg"
-error: 0
path: "/tmp"
filename: "phpomKjXK"
basename: "phpomKjXK"
pathname: "/tmp/phpomKjXK"
extension: ""
realPath: "/tmp/phpomKjXK"
aTime: 2020-11-26 16:22:10
mTime: 2020-11-26 16:22:10
cTime: 2020-11-26 16:22:10
inode: 262126
size: 79694
perms: 0100600
owner: 1000
group: 1000
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
}
I use this mapping (vich_uploader.yaml):
vich_uploader:
db_driver: orm
mappings:
circuits:
uri_prefix: /img/circuits
upload_destination: '%kernel.project_dir%/public/img/circuits'
namer: VichUploaderBundleNamingSmartUniqueNamer
Here are the pieces of code related to the image from my entity :
/**
* @ORMEntity(repositoryClass=CircuitRepository::class)
* @VichUploadable
*/
class Circuit
{
/**
* @ORMColumn(type="string", length=255)
*/
private $thumbnail;
/**
* @VichUploadableField(mapping="circuits", fileNameProperty="thumbnail")
* @var File|null
*/
private $thumbnailFile;
/**
* @var DateTime
*/
private $updated_at;
public function getThumbnail(): ?string
{
return $this->thumbnail;
}
public function setThumbnail(string $thumbnail): self
{
$this->thumbnail = $thumbnail;
return $this;
}
/**
* @return File
*/
public function getThumbnailFile(): ?File
{
return $this->thumbnailFile;
}
/**
* @param File $thumbnailFile
*/
public function setThumbnailFile(?File $thumbnailFile): self
{
$this->thumbnailFile = $thumbnailFile;
if ($this->thumbnailFile instanceof UploadedFile)
$this->updated_at = new DateTime('now');
return $this;
}
}
Finally here is the part of my form that handles the image input :
->add('thumbnailFile', VichImageType::class, [
'label' => 'Vignette',
'allow_delete' => false,
'download_uri' => false,
'image_uri' => false,
'required' => true,
])
Does anyone know why the files I try to upload aren’t saved in my /public/img/circuits folder ?
Thanks.
Source: Symfony Questions
Was this helpful?
0 / 0