Jump to content

Recommended Posts

How do you get the size of a file, for example an audio mp3 file?

Would you use filesize() function?

 

Why ask if you can read that page yourself?

 

 

Description

int filesize ( string $filename )

 

Gets the size for the given file.

 

 

Umm yea? That is what it says it does....

Link to comment
https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727226
Share on other sites

The function is "filesize (f$ilename)"

Example:

<?php

// outputs e.g.  somefile.txt: 1024 bytes

$filename = 'somefile.txt';
echo $filename . ': ' . filesize($filename) . ' bytes';

?>

See here http://www.php.net/manual/en/function.filesize.php for more details

Link to comment
https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727228
Share on other sites

Why ask if you can read that page yourself?

 

 

Description

int filesize ( string $filename )

 

Gets the size for the given file.

 

 

Umm yea? That is what it says it does....

 

The reason why i asked is because I am getting this error:

Warning: filesize() [function.filesize]: stat failed for http://site.com/sitev2/video/nohay/Nadeem Sarwar/2008/hangu_video.wmv in /home/.kernel/site/site.com/sitev2/includes/functions.php on line 110

 

And this is line 110:

<?php echo (" | File size: ".filesize("http://site.com/sitev2/".$row['Ftype']."/".$row['Cat']."/".$row['Speaker']."/".$row['Year']."/".$row['File'].".".$row['FileFormat'])." bytes"); ?>

Link to comment
https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727307
Share on other sites

my first guess would be because of the space between 'Nadeem Sarwar'

 

I removed the spaces and still the same error lol but i think i must doing something wrong.

 

It is good practice to eliminate spaces in any filenames or  directory names. there are tooo many issues that arise because of these. I agree with CV, the function is probably stopping at that space and not finding a correct file there.

 

Well i just tested:

<?php
$file = "audio/nohay/Nadeem_Sarwar/2008/1.mp3";
echo "File: ".$file."<br/>";
if (file_exists($file)){
$file = filesize($file);
echo "File size: ".round($file/1048576)." MB";
}

else {
echo "File doesnt exists!";
}
?>

 

And it's working, so i must doing something wrong above, so i'll check it one more time.

Thanks for the help everyone. :D

Link to comment
https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727601
Share on other sites

Ok i got it working:

 

<?php
//get size of the file
echo " | File size: ";
$file = "".$row['FileType']."/".$row['Cat']."/".$row['Speaker']."/".$row['Year']."/".$row['Link'].".".$row['FileFormat'].""; //LINE 4
if (file_exists($file)){
$file = filesize($file);
echo (round($file/1048576)." MB");
}
else {
echo " File doesn't exists!";
}
?>

 

What i was doing wrong is that I had to add ' "" ' at the beginning and at the end of the $file, you can see what i mean on line 3 and 4. Hope this will help someone.

Link to comment
https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727618
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.