Reputation: 1353
I have a video converter. Here's how it works, you give the URL to the video, it downloads it to the server, then it converts it to mp3. So it works, but the problem is anything over 10 MB (which is only about 30 seconds) crashes the server. I need to know how to upload it in parts, so it doesn't crash the server.
file_put_contents($dest,file_get_contents($url));
Upvotes: 2
Views: 272
Reputation: 28687
The best approach is to download content in chunks. A nice method for doing so can be found in an answer here. In the $callback
function parameter, you can pass a method to convert and write bytes being read.
file_get_contents_chunked($url, 4096, function($chunk, &$handle, $iteration) {
file_put_contents($dest, $chunk, FILE_APPEND);
});
Upvotes: 2