Error in using of file_get_contents to download large files
When i use file_get_contents with $offset != -1 returns false The file i want to get from a URL is very large. Is it possible to use offset parameter with non local file?
The code that i use it:
$content = file_get_contents($encodedurl,false,NULL,$offset,$bloc开发者_开发知识库ksize);
The PHP documentation says:
Seeking (offset) is not supported with remote files. Attempting to seek on non-local files may work with small offsets, but this is unpredictable because it works on the buffered stream.
If your file is very large, then I think your best bet would be to write your own function which simulates a HTTP GET request to the resource. You can then read the file in on a buffered basis, that way you can store, say 16MB, chunks of the file onto disk, and once it has been fully downloaded you can always recombine this into one file. Or process it as chunks as required.
精彩评论