Reputation: 4905
I'm using file_get_contents to get a remote file. My question is, is it possible to ask php to downlaod the first 1mb of a file rather than the whole file? Thank you!
Upvotes: 2
Views: 412
Reputation: 152206
From php.net file_get_contents
string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
You have to specify last maxlen
parameter (in bytes).
maxlen
Maximum length of data read. The default is to read until end of file is reached. Note that this parameter is applied to the stream processed by the filters.
Upvotes: 3
Reputation: 45124
According to my knowledge you can not specify the number of MBs but you can do something like below.
<?php
// Read 14 characters starting from the 21st character
$section = file_get_contents('./people.txt', NULL, NULL, 20, 14);
var_dump($section);
?>
string file_get_contents ( string $filename [, bool $use_include_path
= false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
maxlen - Maximum length of data read. The default is to read until end of file is reached. Note that this parameter is applied to the stream processed by the filters.
Upvotes: 2