1
StofDoctrineExtensionsBundle Uploadable을 사용하여 사용자 엔터티에서 그림을 업로드합니다.StofDoctrineExtensionsBundle 업로드 가능
...
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$uploadableManager = $this->get('stof_doctrine_extensions.uploadable.manager');
$uploadableManager->markEntityToUpload($user, $user->getPath());
...
FormType의 :
...
->add('picture', FileType::class, array(
'label' => 'Picture',
'required' => false
))
...
config.yml : 나는 그것을 테스트 할 때
# StofDoctrineExtensionsBundle Configuration
stof_doctrine_extensions:
default_locale: fr_FR
uploadable:
# Default file path: This is one of the three ways you can configure the path for the Uploadable extension
default_file_path: %kernel.root_dir%/../web/uploads
# Mime type guesser class: Optional. By default, we provide an adapter for the one present in the HttpFoundation component of Symfony
mime_type_guesser_class: Stof\DoctrineExtensionsBundle\Uploadable\MimeTypeGuesserAdapter
# Default file info class implementing FileInfoInterface: Optional. By default we provide a class which is prepared to receive an UploadedFile instance.
default_file_info_class: Stof\DoctrineExtensionsBundle\Uploadable\UploadedFileInfo
orm:
default:
uploadable: true
내가 메시지가 :
컨트롤러에서<?php
namespace Application\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="user")
* @Gedmo\Uploadable(pathMethod="getPath", filenameGenerator="SHA1", allowOverwrite=true, maxSize="100000", allowedTypes="image/jpeg,image/pjpeg,image/png,image/x-png")
*/
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
...
/**
* @ORM\Column(name="picture", type="string", length=255, nullable=true)
* @Gedmo\UploadableFilePath
*/
private $picture;
public function getPath()
{
return '/user';
}
public function setPhoto($photo)
{
$this->photo = $photo;
return $this;
}
public function getPhoto()
{
return $this->photo;
}
...
"/ user"디렉토리를 만들 수 없습니다.
이 문제를 해결하기위한 모든 아이디어. 감사합니다
아니, 난 여전히 지역에서 일하고 있습니다. –
확인. 고마워. 처음에 /를 삭제했습니다. –