I got this error message when trying to send form data post request via POST method.
JavaScript
x
"file_get_contents(http://127.0.0.1:8000/storage/config/xxx.ini): failed to open stream: HTTP request failed! "
Laravel code
JavaScript
$client = new GuzzleHttpClient();
$options = [
'form_params' => [
'service_id' => $id,
'email' => auth()->user()->email
],
'multipart' => [
[
'name' => 'file',
'contents' => file_get_contents('http://127.0.0.1:8000/storage/config/'.$service->config, 'r' ),
'filename' => $service->config
]
]
];
$response = $client->post('http://127.0.0.1:5000/run', $options);
By the way, the file exist if I view at URL. Any idea?
Advertisement
Answer
Instead of making an http request to read the file, use the storage_path
helper:
JavaScript
'contents' => file_get_contents(storage_path('config/'.$service->config, 'r' )),