Php 文件获取内容(#)无法打开流HTTP请求失败
使用上面的代码,我试图为许多用户下载发票。但它抛出文件获取内容(#)无法打开流HTTP请求失败错误。我还使用下面的代码尝试了“Curl”,它也抛出了相同的错误Php 文件获取内容(#)无法打开流HTTP请求失败,php,laravel-4,Php,Laravel 4,使用上面的代码,我试图为许多用户下载发票。但它抛出文件获取内容(#)无法打开流HTTP请求失败错误。我还使用下面的代码尝试了“Curl”,它也抛出了相同的错误 foreach($users as $user){ $url = web_url()."/user/invoice/generate?id=".$user->user_id."&month=".$month."&year=".$year;
foreach($users as $user){
$url = web_url()."/user/invoice/generate?id=".$user->user_id."&month=".$month."&year=".$year;
$html = file_get_contents($url);
$file= public_path(). "/invoice/".$user->user_id."_".$month."_".$year.".pdf";
$headers = array(
'Content-Type' => 'application/pdf',
);
return Response::download($result, $user->user_id."_".$month."_".$year.".pdf", $headers);
}
有谁能告诉我下载许多发票的正确有效方法吗?显然,这是一个错误的URL。您可以通过浏览器访问它吗?不,此URL显示发票页面。。它在浏览器中工作。Echo
$url
-将其复制并粘贴到您的地址栏中。那个有用吗?是的,那个url显示发票页面。试试看前两个答案
foreach($users as $user){
$url = web_url()."/user/invoice/generate?id=".$user->user_id."&month=".$month."&year=".$year;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);
$file= public_path(). "/invoice/".$user->user_id."_".$month."_".$year.".pdf";
$headers = array(
'Content-Type' => 'application/pdf',
);
return Response::download($result, $user->user_id."_".$month."_".$year.".pdf", $headers);
}