To send a large file, over 2 gigabyte, in a HTTP request with PHP is not easy because we can be limited with the memory_limit. Even by setting memory_limit = 5G i was having memory or write issue like : fwrite(): Write of xxxx bytes failed with errno=0 No error I was strugling with Guzzle, and the Laravel HTTP Client for days. I could make it with the PHP curl extension $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://example.com'); $headers = []; $headers[] = 'Content-Type: multipart/form-data'; $headers[] = 'Cookie: something...'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, 1); $path = '/full/path/to/file'; $file = curl_file_create(realpath($path)); $post = [ 'file' => $file, 'other_field' => 'value', ]; $result = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); var_dump($result,$httpcode); Enter fullscreen mode

In a next article i will explain how to chunk upload large file to your Laravel app and not bein limited by your memory limit.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners