Getting link content size
I have a page with more than 100 links(xml files). With some p开发者_如何学编程rework I'm getting the links and saving all the data to a server, but I don't want to save that files which size are smaller than xxKb. How could I get the size?
foreach($links as $link) {
$data = file_get_contents($link);
if (strlen($data) >= $min_size) {
file_put_contents($data, 'some file name on your server');
}
}
You could just use the filesize
method:
foreach($links as $link){
if(filesize($link) > xx){
...
}
}
Try filesize
function. From the Manual:
int filesize ( string $filename )
Gets the size for the given file.
Parameters filename - Path to the file.
Return Values
Returns the size of the file in bytes, or FALSE (and generates an error of level E_WARNING) in case of an error.
精彩评论