Jump to content

Remote File Exists


unkwntech

Recommended Posts

I'm looking for a quick way to check if a remote file exists I have this now:

$url = 'http://money.cnn.com/data/commodities/index.html?cacheBust=' . rand('0', '99999999999');
if(!file_exists($url)){die("I couldn't get the crude price the page is no accessable.");}

But even though I know the page exists this does not work, the PHP manual hints that this is the wrong function for a remote file.

Link to comment
https://forums.phpfreaks.com/topic/116744-remote-file-exists/
Share on other sites

bifor at free dot fr

18-Mar-2008 07:01

A simple function for return the length of a link, or a file.

<?php
function urlfilesize($url,$thereturn) {
if (substr($url,0,4)=='http') {
$x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
$x = $x['content-length'];
            }
else { $x = @filesize($url); }
if (!$thereturn) { return $x ; }
elseif($thereturn == 'mb') { return round($x / (1024*1024),2) ; }
elseif($thereturn == 'kb') { return round($x / (1024),2) ; }
}

?>

The example :
<?php
echo urlfilesize('http://www.tayo.fr/remote-irc-tutoriel.php','mb')

?>

 

Link to comment
https://forums.phpfreaks.com/topic/116744-remote-file-exists/#findComment-600355
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.