0
A
답변
0
데이터베이스에 고유 한 이름과 상점 이름으로 폴더에 저장하십시오.
이미지를 업로드하려면 양식에 FileType 필드 (here)를 사용할 수 있습니다. 당신은 내가 기억하는 양식 유효성 검사는 Imagetype을 사용할 수 있으며 여기에 폴더에 파일을 저장하고 데이터베이스에 파일 이름을 저장하는 몇 가지 코드 :
$user = new User();
$form = $this->createForm(UserForm::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$img = $user->getPhoto();
$fileName = md5(uniqid()).'.'.$img->guessExtension();
$user->setPhoto($fileName);
// Move the file to the directory where brochures are stored
$img->move(
$this->getParameter('user_image_directory'),
$fileName
);
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
}
을 그리고 당신은 IMG를 표시 할 때에 표시가 비슷한 방식으로 나뭇 가지를 작성한 후 $ user-> getPhoto()로 파일 이름을 읽고이를 템플릿으로 보내면 템플릿에서 user.getPhoto()를 호출했을 때 버그가 있습니다. 아마도 나만의 것일 것입니다 :
img src="{{ asset('media/users/') }}{{ filename }}"></div>
시도해 보았던 (구현 된) 부분과 붙어있는 부분을 보여줍니다. 질문을 향상 시키려면 [어떻게 좋은 질문을합니까?] (http://stackoverflow.com/help/how-to-ask)를 읽고 질문을 적절하게 업데이트하십시오. –
물론, 나는 문제없이 [설치 절차] (https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/installation.md)를 따른다. [yml 매핑] (https : //github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/mapping/yaml.md). 이것은 doctrine : schema : update에 영향을 미치지 않습니다. 필요한 경우 구성을 첨부 할 수 있습니다. –
예, 코드를 추가하여 구현 방법을 확인하십시오. –