0 レビュー
0 回答
curlが見つけてもPHPファイルが見つかりません
PHPでファイルを作成し、それを名前を付けて保存しています
$job->fullFileName = realpath(".")."/abc.txt";
CURLでこのパスを使用すると(他のサービスと一緒にメールを送信するため)、正しく機能します。私が受け取った電子メールには、期待どおりに添付ファイルがあります。したがって、明らかにファイルが存在し、CURLがそれを読み取ることができます。
$fileContent = '';
if (function_exists('curl_file_create')) {
// php 5.6+
$fileContent = curl_file_create($job->fullFileName);
} else {
$fileContent = '@' . realpath($job->fullFileName);
}
$params = array(
....
'files['.$job->fileName.'.epub'.']' => $fileContent
);
print_r($params);
$request = $url.'api/mail.send.json';
// Generate curl request
$session = curl_init($request);
// Tell curl to use HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
// Tell curl that this is the body of the POST
curl_setopt ($session, CURLOPT_POSTFIELDS, $params);
// Tell curl not to return headers, but do return the response
curl_setopt($session, CURLOPT_HEADER, false);
// Tell PHP not to use SSLv3 (instead opting for TLS)
curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// obtain response
$response = curl_exec($session);
curl_close($session);
しかし、ユーザーが直接ダウンロードできるようにしようとすると、PHPはそれを見つけられませんでした:
$app->get('/download', function (Request $request) use ($app) {
$params = $request->query;
$id = (int)$params->get('id', '');
if (!$id) {
return new Response("Job not found", 404);
}
$job = Job::fromId($app, $id);
if (!$job->fullFileName) {
return new Response("File not found", 404);
}
if (!file_exists($job->fullFileName)) {
return new Response("PHP give up", 404); //<<<------ IT RETURN THIS LINE!!!
}
$app['monolog']->error("[api.download] attempt to download $job->fullFileName");
// Without the check above, it will throw File Not found exception right here
$response = new BinaryFileResponse($job->fullFileName);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
return $response;
});
何が恋しかったですか?
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。