序章
私は使っている:
- ウィンドウズ 10 プロ
- XAMPP と PHP v7.0.9
- symfony v3.1.6
- ドクトリン v2.5.4
- Tree 構造を管理するためのStofDoctrineExtensionsBundle [1] 。
- ファイルをアップロードするためのOneupUploaderBundle [2]
- ファイルシステムの抽象化のためのOneupFlysystemBundle [3]
設定中
ツリー構造 (ディレクトリとファイルを表す) をセットアップしOneupUploaderBundle
、Flysystem
エンドポイントを使用してファイルをアップロードしました。
data
ファイルのアップロードは、プロジェクトのルート フォルダーに存在するという名前のフォルダーにアップロードするように構成されています。アップロードは正常に機能しており、さまざまなアップロード用のカスタム サブディレクトリを含むパスも機能します (たとえばdata/project_001/test1.txt
、 とdata/project_002/test2.txt
)。
問題
ユーザーが以前にアップロードしたファイルを提供する必要があります。
この時点で
エラーが発生しています (コントローラーの末尾が 1 の場合)
The file "Project_9999/2_Divi/bbb.pdf" does not exist 500 Internal Server Error - FileNotFoundException
とエラー(コントローラーエンディング2付き)
Catchable Fatal Error: Object of class League\Flysystem\File could not be converted to string 500 Internal Server Error - ContextErrorException
$exists
戻ることに注意してくださいtrue
-ファイルは間違いなくそこにあります!
コード
config.yml の関連部分
oneup_uploader:
mappings:
gallery:
storage:
type: flysystem
filesystem: oneup_flysystem.gallery_filesystem
frontend: blueimp
enable_progress: true
namer: app.upload_unique_namer
allowed_mimetypes: [ image/png, image/jpg, image/jpeg, image/gif ]
max_size: 10485760s
oneup_flysystem:
adapters:
my_adapter:
local:
directory: "%kernel.root_dir%/../data"
filesystems:
gallery:
adapter: my_adapter
コントローラーのアクション
<?php
public function projectDownloadFileAction($file_id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('AppBundle:FileTree');
$ultra = $this->get('app.ultra_helpers');
$selected_file = $repo->getFileTreeNodeByIdArray($file_id);
$item_name = $selected_file[0]['item_name'];
$item_extension = $selected_file[0]['item_extension'];
$activeProject = $this->get('session')->get('active_project');
$activeProjectSelectedNodePath = $this->get('session')->get('active_project_selected_node_path');
$item_file_name = $item_name .'.'. $item_extension;
$complete_file_path = $activeProject['secret_path'] . $activeProjectSelectedNodePath .'/'. $item_file_name;
dump($complete_file_path);
ENDING -1-
ENDING -2-
}
エンディング1
$downloadable_file = new \SplFileInfo($complete_file_path);
dump($downloadable_file);
$response = new BinaryFileResponse($downloadable_file);
// Set headers
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-Type', mime_content_type($downloadable_file));
$response->headers->set('Content-Disposition', $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$downloadable_file->getFilename()
));
return $response;
エンディング2
$filesystem = $this->get('oneup_flysystem.gallery_filesystem');
$exists = $filesystem->has($complete_file_path);
if (!$exists)
{
throw $this->createNotFoundException();
}
dump($exists);
$downloadable_file = $filesystem->get($complete_file_path);
dump($downloadable_file);
$response = new BinaryFileResponse($complete_file_path);
$response->trustXSendfileTypeHeader();
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
return $response;
更新 1
Ending 1
変数 $complete_file_path に絶対パスを指定しようとしましたが、エラーしか発生しませんでした。例えば:
File not found at path: C:\DEV\tree_and_upload\data\Project_9999\1_Viens\test1.txt 500 Internal Server Error - FileNotFoundException
File not found at path: C:/DEV/tree_and_upload/data/Project_9999/1_Viens/test1.txt 500 Internal Server Error - FileNotFoundException
しかし、違いはありませんでした-アクセスエラーが発生しました。data
おそらく、Symfony はプロジェクトのルートにあるフォルダーへのアクセスを積極的に制限しています...
質問
data
プロジェクトのルート フォルダーにあるフォルダーからファイルを提供し、アダプターFlysystem
でファイルシステム抽象化レイヤーを使用するにはどうすればよいですか?Local
結論
私は何が欠けていますか?
お知らせ下さい。
お時間と知識をありがとうございました。