Music download forum - Your music community: Suggestion for displaying filesize - Music download forum - Your music community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Suggestion for displaying filesize

#1 User is offline   olke

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 4
  • Joined: 13-November 12

Posted 13 November 2012 - 12:46 PM

Hey.
Really like what you're doing, but I'm missing a few things.
First up is the bitrate/quality, and I read in a previous topic that you didn't have that you couldn't resolve that.

The next best thing would be to display filesize.
If you don't have that available in the database, you should be able to get it with the PHP filesize-function.

php_net/manual/en/function.filesize.php

It will return filesize in bytes, so some formatting wrapper would have to be used. There are plenty of examples on the function-page, but I would suggest something like this:

<?php

function get_filesize($file) {
if (preg_match('/^https?\:\/\//', $file)) {
return get_filesize_from_url($file);
}
else {
return filesize($file);
}
}

function get_filesize_from_url($file) {

$ch = curl_init($file);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$data = curl_exec($ch);
curl_close($ch);

if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {

// Contains file size in bytes
$contentLength = (int)$matches[1];

return $contentLength;
}
}

function human_filesize($bytes, $decimals = 2) {
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}

// echo human_filesize(get_filesize("/path/to/local/file.mp3"));
echo human_filesize(get_filesize("_www.google_com/images/srpr/logo3w.png"));

?>

The function "get_filesize()" would work with either a url (http, https) or a local file-path.
human_filesize() will format from bytes to K/M/G etc.

Would this be possible?

Regards
0

#2 User is offline   Dreamdemon

  • Administrator
  • Icon
  • Group: Administrators
  • Posts: 129
  • Joined: 05-October 09

Posted 26 December 2012 - 12:37 PM

Thanks for taking part in the work of the site. Realized this feature through extra popping window (see ruler besides the song title).
The elevator to success is out of service, but the stairs are always open.
0

#3 User is offline   olke

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 4
  • Joined: 13-November 12

Posted 08 January 2013 - 10:01 AM

View PostDreamdemon, on 26 December 2012 - 01:37 PM, said:

Thanks for taking part in the work of the site. Realized this feature through extra popping window (see ruler besides the song title).


I just realized this, very greatful! Glad to help also.
0

#4 User is offline   olke

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 4
  • Joined: 13-November 12

Posted 18 June 2013 - 01:00 PM

View PostDreamdemon, on 26 December 2012 - 01:37 PM, said:

Thanks for taking part in the work of the site. Realized this feature through extra popping window (see ruler besides the song title).


Hi!
This feature stopped working... It always displays 0MB.
Could you fix it?

Cheers.
0

#5 User is offline   Dreamdemon

  • Administrator
  • Icon
  • Group: Administrators
  • Posts: 129
  • Joined: 05-October 09

Posted 24 June 2013 - 11:28 AM

Fixed this long time ago. Thank you for your feedback
The elevator to success is out of service, but the stairs are always open.
0

#6 User is offline   olke

  • Newbie
  • Pip
  • Group: New Members
  • Posts: 4
  • Joined: 13-November 12

Posted 06 August 2013 - 05:11 PM

View PostDreamdemon, on 24 June 2013 - 12:28 PM, said:

Fixed this long time ago. Thank you for your feedback


You sure?
The ruler is there, but when you click it the page only displays "Size: 0 Mb" for all files.
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users