Reputation: 690
The issue I run into is that I am trying to download a sample file from my server, but only 100 bytes get saved and never the full file, when on my localhost I can download the whole file.
The code I use is:
// https://pgli96.oloadcdn.net/dl/l/7Cfk7N6ajhk19Byr/tr6gjooZMj0/big_buck_bunny_240p_5mb.3gp.mp4?mime=true to view the file in browser
$url = 'https://pgli96.oloadcdn.net/dl/l/H8-l9DTbn5X1eBid/tr6gjooZMj0/big_buck_bunny_240p_5mb.3gp.mp4';
set_time_limit(0);
$fp = fopen (storage_path('app/download/test.mp4'), 'w+');
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
I am really baffled as to why it would not work on a production Linux server. Curl is installed there as well. Any help would be highly appreciated!
Thanks so much.
Upvotes: 0
Views: 1000
Reputation: 6793
The CDN provider blocks calls from different locations. When loading the same URL from your production system, the CDN provider realizes that the ISP has changed since the resource was requested.
When I open that URL, I only get the answer
{"status":403,"msg":"download ISP is different to request ISP. request: AS20115 download: AS3320"}
This answer contains exactly 98 bytes, adding a CRLF in the end makes exactly 100 bytes.
Check your file contents and you will see, it is not the first 100 bytes of the resource, but exactly the answer I quoted above.
To check the file, just use cat
(on the shell) to display its contents:
> cat <filename>
I guess, the only solution will be to generate a request for the resource you want to load directly from the server (maybe you can use lynx
to do that)
Upvotes: 2