unkwntech Posted July 26, 2008 Share Posted July 26, 2008 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 More sharing options...
unkwntech Posted July 26, 2008 Author Share Posted July 26, 2008 I suppose I should ask how to get the size of this file since: $data = fread($fh, filesize($url)); doesn't work. Link to comment https://forums.phpfreaks.com/topic/116744-remote-file-exists/#findComment-600353 Share on other sites More sharing options...
discomatt Posted July 26, 2008 Share Posted July 26, 2008 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 More sharing options...
discomatt Posted July 26, 2008 Share Posted July 26, 2008 Did you want to get the filesize, or simply copy the contents of a remote file into a variable/local file? Link to comment https://forums.phpfreaks.com/topic/116744-remote-file-exists/#findComment-600359 Share on other sites More sharing options...
unkwntech Posted July 26, 2008 Author Share Posted July 26, 2008 Well I'm loading it into a variable and I need the size for fgets(). And I tryed that script and it returns 0. Link to comment https://forums.phpfreaks.com/topic/116744-remote-file-exists/#findComment-600361 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.