note 37049 rejected from function.file-get-contents by pollita

From: Date: Sat, 01 Nov 2003 04:38:39 +0000
Subject: note 37049 rejected from function.file-get-contents by pollita
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-59614@lists.php.net to get a copy of this message
Note Submitter: baangie@msn.com ---- 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. :)

« previous php.notes (#59614) next »