我制作了一个api,我在其中发送图像链接,然后用户可以从这个链接下载图像
第一个问题
$path=(公共路径(“图像”)$文件名);
Echo$path会是这样的
“C:\wamp\www\jobpost\public\imagesPerson.PNG”//why it not put\after images”
我这样做但错误发生
$path=(公共路径(“图像”)。"\". $文件名);
第二个问题
之后我测试图像下载与否我手动放置链接
返回响应::下载(“C:\wamp\www\jobpost\public\images\Person.PNG”);
出错
调用未定义的方法Illumate\Auth\Access\Response::dOwload()
我已经在控制器的顶部使用了这个
使用照明\认证\访问\响应;//i对此进行评论并使用
使用Response//error-remove
第三个问题
当我使用响应时
返回响应::下载(“C:\wamp\www\jobpost\public\images\Person.PNG”);
错误发生
调用未定义的方法Symfony\Component\HttpFoundation\BinaryFileResponse::header()
我搜索了很多这是我的标题
$headers = array(
'Content-Type: PNG',
);
我把这个换掉
return Response::download("C:\wamp\www\jobpost\public\images\Person.PNG");
由此
return( Response::download( "C:\wamp\www\jobpost\public\images\Person.PNG", 'filename.PNG', $headers) );
但问题仍然没有解决
我的cors。php
Cors.php
$headers = [
'Access-Control-Allow-Origin'=> '*',
'Access-Control-Allow-Methods'=> 'POST, GET, OPTIONS, PUT, DELETE',
'Access-Control-Allow-Headers'=> 'Content-Type, X-Auth-Token, Origin',
'Access-Control-Allow-Credentials' => 'true'
];
if($request->getMethod() == "OPTIONS") {
// The client-side application can set only headers allowed in Access-Control-Allow-Headers
return Response::make('OK', 200, $headers);
}
$response = $next($request);
foreach($headers as $key => $value)
$response->header($key, $value);
return $response;
使用响应()-