0
我有一个数据流,我需要将其保存在PDF
文件中,然后将该文件存储在已存在的目录中,即Documents/pdf
。该目录与src
,app
,web
目录处于同一级别,并具有写入其中的所有权限。Symfony2文件系统 - 在现有目录中保存数据流
在我的解决方案中,我始终将文件保存在web
目录下。我想要该文件在Documents/pdf
之下。这是我的控制器:
/**
* @Route("/api/savePdf", name = "save_pdf")
* @Method("POST")
**/
public function savePdfAction(Request $request) {
$pdfPath = $this->get("kernel")->getRootDir() . '/../Documents/pdf/';
$data = $request->getContent();
$name = 'file.pdf';
$dateNow = new \DateTime('now');
$date = $dateNow->format('Y-m-d H-i-s');
$fileName = $date.$name;
try {
$fs = new Filesystem();
$fs->dumpFile($fileName, $data);
move_uploaded_file($fileName, $pdfPath.$fileName);
return new Response ("File saved correctly", 200, array('Content-Type' => 'application/json'));
}
catch(IOException $e) {
return new Response ("Error!", 500, array('Content-Type' => 'application/json'));
}
return new Response();
}
没有错误?只存储在错误的路径?尝试'死(var_dump($ this-> get(“kernel”) - > getRootDir()));' – Matteo
@Matteo是的,没有错误。这是结果 - >字符串(30)“/ home/user/AppBundle/app” – Dygne