파일 형식이 포함 된 양식 (News 및 NewsFiles 컬렉션)이 있습니다. 내 localhost 컴퓨터에서 모든 것이 잘 작동합니다 : News 및 NewsFiles 엔티티가 지속되고 파일이 업로드됩니다. 하지만 파일을 추가하려고하면 프로덕션 서버 포스트 요청이 중지됩니다. 파일이 업로드되고 엔티티가 db에 존재하지 않고 게시 요청이 상태 : 302에 의해 중지되고 다음 페이지로 리디렉션하지 않고 빈 페이지를 반환합니다.PHP 게시물 요청이 빈 페이지로 중단되었습니다
public function createAction(Request $request) {
$entity = new News();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
// PROBLEM APPEARS HERE - WHEN TRY TO FLUSH
$em->flush();
$this->get('session')->getFlashBag()->add(
'success', 'Wykonano pomyślnie!'
);
return $this->redirect($this->generateUrl('website_admin_panel_news'));
}
return $this->render('WebsiteNewsBundle:News:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
News 엔티티 만 추가하려고해도 문제가 없습니다. 엔티티를 편집 할 때도 마찬가지입니다.
로그 : logs
INFO - Matched route "news_update" (parameters: "_controller": "Website\NewsBundle\Controller\NewsController::updateAction", "id": "6", "_route": "news_update")
DEBUG - Read SecurityContext from the session
DEBUG - Reloading user from user provider.
DEBUG - Username "admin" was reloaded from user provider.
DEBUG - Write SecurityContext in the session
나는 문제가 서버 측에서 생각, 내가 관리자에 기록하지만 나는 그가 변경하는 것을 그에게 제안 할 필요는 그래서 그는 전문가가 아닙니다. .. 어떤 아이디어? 시간 초과 문제가 될 수 있습니까?
편집 : 자세한 정보가 있습니다. 이 문제는 move() 함수에서 발생합니다. 그것은 작은 파일 (1px - 539 바이트)을 보내려고했기 때문에 시간 초과 문제가 아니며 여전히 작업을 수행하지 않습니다. 은 여기 내 법인 업로드하는 것입니다
<?php
namespace Website\NewsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
// use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Validator\Constraints;
/**
*
*
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="NewsFiles")
*
*/
class NewsFile {
private $temp;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
*/
private $owner;
/**
*
*/
private $file;
/**
* @ORM\Column(type="string", length=255)
*
*/
private $name;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\ManyToOne(targetEntity="News", inversedBy="newsFiles")
* @ORM\JoinColumn(name="news_id", referencedColumnName="id")
*/
protected $news;
/**
* @var string
*
* @ORM\Column(name="path", type="string", length=255)
*/
private $path;
/**
* @var string
*
* @ORM\Column(type="boolean", nullable=false)
*/
private $isMain;
/**
* Now we tell doctrine that before we persist or update we call the updatedTimestamps() function.
*
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updatedTimestamps() {
if ($this->getCreated_At() == null) {
$this->setCreated_At(new \DateTime(date('Y-m-d H:i:s')));
}
}
public function setId($id) {
$this->id = $id;
}
public function getId() {
return $this->id;
}
public function setOwner($owner) {
$this->owner = $owner;
}
public function getOwner() {
return $this->owner;
}
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
public function setPath($path) {
$this->path = $path;
}
public function getPath() {
return $this->path;
}
/**
* Set created_at
*
* @param string $created_at
* @return File
*/
public function setCreated_at($created_at) {
$this->created_at = $created_at;
return $this;
}
/**
* Get created_at
*
* @return string
*/
public function getCreated_at() {
return $this->created_at;
}
/**
* Sets file.
*
* @param UploadedFile $file
*/
public function setFile(UploadedFile $file = null) {
$this->file = $file;
// check if we have an old image path
if (isset($this->path)) {
// store the old name to delete after the update
$this->temp = $this->path;
$this->path = null;
} else {
$this->path = 'initial';
}
}
/**
* Get file.
*
* @return UploadedFile
*/
public function getFile() {
return $this->file;
}
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() {
return 'uploads/News/' . $this->getNews()->getId();
}
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload() {
if (null !== $this->file) {
// zrób cokolwiek chcesz aby wygenerować unikalną nazwę
$this->setName(sha1(uniqid(mt_rand(), true)));
$this->setPath($this->getName() . '.' . $this->file->guessExtension());
}
}
/**
* @ORM\PostPersist()
* @ORM\PostUpdate()
*/
public function upload() {
// zmienna file może być pusta jeśli pole nie jest wymagane
if (null === $this->file) {
return;
}
// HERE HE CANCEL HIS WORK
$this->getFile()->move($this->getUploadRootDir(), $this->path);
// check if we have an old image
if (isset($this->temp)) {
echo "isset temp";
// delete the old image
unlink($this->getUploadRootDir() . '/' . $this->temp);
// clear the temp image path
$this->temp = null;
}
$this->file = null;
}
/**
* @ORM\PostRemove()
*/
public function removeUpload() {
if ($file = $this->getAbsolutePath()) {
unlink($file);
}
}
/**
* Set news
*
* @param string $news
* @return News
*/
public function setNews($news) {
$this->news = $news;
return $this;
}
/**
* Get news
*
* @return string
*/
public function getNews() {
return $this->news;
}
/**
* Set isMain
*
* @param string $isMain
* @return IsMain
*/
public function setIsMain($isMain) {
$this->isMain = $isMain;
return $this;
}
/**
* Get isMain
*
* @return string
*/
public function getIsMain() {
return $this->isMain;
}
}
당신이 자극 환경에 캐시를 삭제 시도? – stevenll
예, 여러 번. ftp를 통해서만 명령 행에 접근 할 수 없으므로 캐시에서 파일을 지우고 권한을 777-R로 설정했습니다 ... – rKow
app.php 파일로 가서 디버그를 켜십시오 : $ kernel = new AppKernel ('prod', true); 그러면 더 나은 오류 메시지가 나타날 수 있습니다. – Cerad