Jump to content

Recommended Posts

Posted

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? :)


Posted

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!");?>
Posted

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)?

Posted
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... :rolleyes: I'll try it out later! :D

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...