Symfony2.3 + Sonata Admin + FosUserBundle + SonataUserBundle을 사용하고 있습니다. 모든 것이 잘 작동합니다. 사용자에FOS 사용자 파일 업로드
:이 큰 작업 및 사용자 자신의 이미지를 업로드 할 때 다음 경로 I가이 경로와 S3의 모든 사용자 이미지 업로드를 변경할
/web/uoloads/documents/imagesname.jpg
업로드되는 사용자 이미지 업로드 기능을 만들었습니다.
이 사용자 엔티티입니다 : -
/**
* @ORM\Entity
* @ORM\Table(name="user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $path;
/**
* @Assert\Image(maxSize="6000000", mimeTypesMessage="Please select a valid image")
*/
private $file;
public function __construct()
{
parent::__construct();
}
public function getAbsolutePath()
{
return null === $this->path
? null
: $this->getUploadRootDir().'/'.$this->path;
}
public function getWebPath()
{
return null === $this->path
? null
: $this->getUploadDir().'/'.$this->path;
}
protected function getUploadRootDir()
{
// the absolute directory path where uploaded
// documents should be saved
return __DIR__.'/../../../../web/'.$this->getUploadDir();
}
protected function getUploadDir()
{
// get rid of the __DIR__ so it doesn't screw up
// when displaying uploaded doc/image in the view.
return 'uploads/documents';
}
/**
* Sets file.
*
* @param UploadedFile $file
*/
public function setFile(UploadedFile $file = null)
{
$this->file = $file;
}
/**
* Get file.
*
* @return UploadedFile
*/
public function getFile()
{
return $this->file;
}
public function upload()
{
// the file property can be empty if the field is not required
if (null === $this->getFile()) {
return;
}
// use the original file name here but you should
// sanitize it at least to avoid any security issues
// move takes the target directory and then the
// target filename to move to
$this->getFile()->move(
$this->getUploadRootDir(),
$this->getFile()->getClientOriginalName()
);
// set the path property to the filename where you've saved the file
$this->path = $this->getFile()->getClientOriginalName();
// clean up the file property as you won't need it anymore
$this->file = null;
}
/**
* Set path
*
* @param string $path
* @return Image
*/
public function setPath($path)
{
$this->path = $path;
return $this;
}
/**
* Get path
*
* @return string
*/
public function getPath()
{
return $this->path;
}
}
이 Get service container from entity in symfony 2.1 (Doctrine) 작동 및 오류 표시 FOS 사용자에없는 것처럼 기업이 아니라 일반 전화 서비스 conatiner에서 서비스 컨테이너를 통해이 경로를 변경합니다.
혼란 스럽습니다. 어느 누구도 나에게이 길을 어떻게 바꿀 수 있고 s3으로 갈 수 있는지 제안 해 준다. User Entity에서 서비스 컨테이너를 성공적으로 호출하면 내 문제는 해결되지만 FOS User Bundle에서는 정상적인 심포니 서비스 호출이 작동하지 않습니다.
감사합니다.
답변 주셔서 감사합니다.이 프로젝트는 현재 실행 중이므로 구멍의 것들을 변경하고 싶지는 않습니다. – Sid