zeeshan_haider000 Posted December 31, 2008 Share Posted December 31, 2008 How do you get the size of a file, for example an audio mp3 file? Would you use filesize() function? Quote Link to comment https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/ Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 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.... Quote Link to comment https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727226 Share on other sites More sharing options...
.josh Posted December 31, 2008 Share Posted December 31, 2008 That's what the manual would have you believe... Quote Link to comment https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727227 Share on other sites More sharing options...
Absorbator Posted December 31, 2008 Share Posted December 31, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727228 Share on other sites More sharing options...
zeeshan_haider000 Posted January 1, 2009 Author Share Posted January 1, 2009 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727307 Share on other sites More sharing options...
.josh Posted January 1, 2009 Share Posted January 1, 2009 my first guess would be because of the space between 'Nadeem Sarwar' Quote Link to comment https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727332 Share on other sites More sharing options...
chronister Posted January 1, 2009 Share Posted January 1, 2009 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. nate Quote Link to comment https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727364 Share on other sites More sharing options...
zeeshan_haider000 Posted January 1, 2009 Author Share Posted January 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727601 Share on other sites More sharing options...
zeeshan_haider000 Posted January 1, 2009 Author Share Posted January 1, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/139046-get-size-of-a-file/#findComment-727618 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.