Let's say I want XML Files only with upto 10MB to be loaded from a remote server.
Something like
$xml_file = "http://example.com/largeXML.xml";// size= 500MB
//PRACTICAL EXAMPLE: $xml_file = "http://www.cs.washington.edu/research/xmldatasets/data/pir/psd7003.xml";// size= 683MB
/*GOAL: Do anything that can be done to hinder this large file from being loaded by the DOMDocument without having to load the File n check*/
$dom = new DOMDocument();
$dom->load($xml_file /*LOAD only IF the file_size is <= 10MB....else...echo 'File is too large'*/);
How can this possibly be achieved?.... Any idea or alternative? or best approach to achieving this would be highly appreciated.
I checked PHP: Remote file size without downloading file but when I try with something like
var_dump(
curl_get_file_size(
"http://www.dailymotion.com/rss/user/dialhainaut/"
)
);
I get string 'unknown' (length=7)
When I try with get_headers
as suggested below, the Content-Length is missing in the headers, so this will not work reliably either.
Please kindly advise how to determine the length
and avoid sending it to the DOMDocument
if it exceeds 10MB
var_dump(filesize("http://www.cs.washington.edu/research/xmldatasets/data/pir/psd7003.xml"))
– Twaddlefilesize()
..... invar_dump(filesize('https://www.w3.org/TR/2001/REC-xsl-20011015/xslspec.xml'))
– Twaddle