File Size On External Files?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    File Size On External Files?

    iv been try to add file sizes to external links in the vault
    i have got it half working but its not bringing back size of all files
    is there something im doing wrong? or is it not possible with all files on all servers?
    Code:
    ///$file = "http://somesite.con/files/music.mp3";////example file
    $something = get_headers($file, 1);        
    $size = $something['Content-Length'];
    echo "<a href=\"$file\">music.mp3</a> $size bytes
    ";

    #2
    i guess i could have if(($size=="")||($size=="0")){
    $size = "unkown";
    }

    but its not really the solution

    Comment


      #3
      solved used curl instead

      Comment


        #4
        Here it can be done with python ;)
        Code:
        import urllib2
        
        url = &#39;[url]http://abc.com/dir/file1.mp3&#39;[/url]
        usock = urllib2.urlopen(url)
        data = usock.read()
        size = data.__len__() # size in bytes
        size = size / 1024.0 # in KB (Kilo Bytes)
        size = size / 1024.0 # size in MB (Mega Bytes)

        Comment


          #5
          or u can add a function
          Code:
          function urlfilesize($url,$thereturn) {
          if (substr($url,0,4)==&#39;http&#39;) { 
          $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
          $x = $x[&#39;content-length&#39;];
                      }
          else { $x = @filesize($url); }
          if (!$thereturn) { return $x; }
          elseif($thereturn == &#39;mb&#39;) { return round($x / (1024*1024),2); }
          elseif($thereturn == &#39;kb&#39;) { return round($x / (1024),2); }
          }
          sigpiceeeeerrr....

          Comment


            #6
            get_headers ????????

            Comment

            Working...
            X