gamehead200 Posted April 17, 2004 Posted April 17, 2004 Hello once again, everyone!I am in the process of creating a script that gets the file size of a remote file. Then, if the file is a certain size, it displays a certain message, and if its a different size, it displays a different message. I have looked at all of the remote file size scripts submitted by people on PHP.net but have had no luck.Can someone please guide me in the right direction?
zivan56 Posted April 17, 2004 Posted April 17, 2004 Got this from PHP.NET<?phpfunction remote_file_size ($url){ $head = ""; $url_p = parse_url($url); $host = $url_p["host"]; $path = $url_p["path"]; $fp = fsockopen($host, 80, $errno, $errstr, 20); if(!$fp) { return false; } else { fputs($fp, "HEAD ".$url." HTTP/1.1\r\n"); fputs($fp, "HOST: dummy\r\n"); fputs($fp, "Connection: close\r\n\r\n"); $headers = ""; while (!feof($fp)) { $headers .= fgets ($fp, 128); } } fclose ($fp); $return = false; $arr_headers = explode("\n", $headers); foreach($arr_headers as $header) { $s = "Content-Length: "; if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) { $return = substr($header, strlen($s)); break; } } return $return;} print ("Google logo is " . remote_file_size ("http://www.google.it/intl/it_it/images/logo.gif") . " bytes!");?>
gamehead200 Posted April 17, 2004 Author Posted April 17, 2004 I tried this one before... I'll see if it works again, I guess... Edit: Still no luck!
zivan56 Posted April 17, 2004 Posted April 17, 2004 have you changed "dummy" to the actual domain name of the server your a connecting to? Are you sure you have fopen privilages for remote urls? are you sure the server supports the HEAD command (some uncommon servers dont)?
gamehead200 Posted April 18, 2004 Author Posted April 18, 2004 have you changed "dummy" to the actual domain name of the server your a connecting to?Wow... How stupid can I get!? Thanks for showing me that, zivan... I'll try it out later!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now