note 37049 added to function.file-get-contents

From: Date: Fri, 31 Oct 2003 20:40:21 +0000
Subject: note 37049 added to function.file-get-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-59601@lists.php.net to get a copy of this message
Using Dave's example, I was able to generate a function to check the filesize of a file on a remote server quickly, cleanly, and accurately. All I had to use, was the following... I pulled the link from the DB within an array called $row[]. Then did the following: if($row['link'] != ""){ $fp = $this->file_get_contents( $row['link']); if (!$fp){ if($linkcheck == 1){ $linked = FALSE; $row['linksize'] = "Unavailable"; } else { $row['linksize'] = "Unavailable"; } } elseif(@strlen($fp) < 1024){ $row['linksize'] = "(Approx)".@round(@strlen($fp),4)." Bytes"; } else { $row['linksize'] = "(Approx)".@round((@strlen($fp)/1024),2)." kB"; } } And set up this function for file get contents as the function itself didn't do anything on my version (call to undefined function)... function file_get_contents($f) { ob_start(); $retval = @readfile($f); if (false !== $retval) { // no readfile error $retval = ob_get_contents(); } ob_end_clean(); return $retval; } This is correctly pulling the filesize for remotely and even local files...just what I wanted. And as an FYI a google search on using php to pull remote file size turned up nothing that actually worked when I tried it myself. :) ---- Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37049 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37049&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37049&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#59601) next »