file get contents(#) failed to open stream HTTP request failed

413 Views Asked by At
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);
                }

Using above code, i m trying to download invoices for many users. But it throws file get contents(#) failed to open stream HTTP request failed error. I also tried "Curl" using the below code, it also throws same error.

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);
                }       

Can anyone suggest me the correct and efficient way to download many invoices?

0

There are 0 best solutions below