TapeGun007 Posted June 6, 2010 Share Posted June 6, 2010 I have a folder with about 2,000 files in it. Most are .mp3's and .pdf files. The largest file is 50 MB. This line of code: $File_Size=filesize('Music_Library/'.$file); is causing this error: Warning: filesize() [function.filesize]: stat failed for.......... I add up the total file size so at the bottom of the page it will list the total number of files and total filesize that all files are taking up. Works fine on my old php 4.2 server, but simply gives this error on 5.1. Most of the help I found on Google doesn't seem to deal with my specific error. Quote Link to comment https://forums.phpfreaks.com/topic/203996-filesize-error-worked-in-php-42-not-51/ Share on other sites More sharing options...
ZachMEdwards Posted June 6, 2010 Share Posted June 6, 2010 Try this: if(file_exists('Music_Library/'.$file)) { $File_Size=filesize('Music_Library/'.$file); echo 'File Size: '.$File_Size; } else { echo 'File doesn\'t exist!'; } Quote Link to comment https://forums.phpfreaks.com/topic/203996-filesize-error-worked-in-php-42-not-51/#findComment-1068437 Share on other sites More sharing options...
PFMaBiSmAd Posted June 6, 2010 Share Posted June 6, 2010 Given that you did not post the most important part of the error message (the part that states why it failed), I'll guess that your path is either not correct or the capitalization is not correct and you are on an operating system that is case sensitive. Quote Link to comment https://forums.phpfreaks.com/topic/203996-filesize-error-worked-in-php-42-not-51/#findComment-1068439 Share on other sites More sharing options...
TapeGun007 Posted June 6, 2010 Author Share Posted June 6, 2010 Ok... so that's weird. I get the File doesn't exist! like 1,000 times, and then it goes ahead and executes the code below and spits out the filenames and their sizes... how could the filename not exists and yet it executes fine? The original error was this: Warning: filesize() [function.filesize]: stat failed for Music_Library/zzc_this is a test file - delete.avi in /home2/sanjose3/public_html/downloads.php on line 22 I didn't think any of that other info would be all that useful. I actually thought the code you gave me didn't mean anything since the files are obviously there and the path must be correct since it executes the code... this is where I'm puzzled. Quote Link to comment https://forums.phpfreaks.com/topic/203996-filesize-error-worked-in-php-42-not-51/#findComment-1068441 Share on other sites More sharing options...
TapeGun007 Posted June 6, 2010 Author Share Posted June 6, 2010 So... after playing around a bit more. The code still executes correctly and display the file names and sizes. Granted, your code that you had me put in says the file does not exists. Why would it say that the file is missing when it's clearly present? Quote Link to comment https://forums.phpfreaks.com/topic/203996-filesize-error-worked-in-php-42-not-51/#findComment-1068447 Share on other sites More sharing options...
TapeGun007 Posted June 6, 2010 Author Share Posted June 6, 2010 PFMaBiSmAd, I think you are right. After reviewing code previous... I convert all the filenames to lowercase because when a user searches for a filename, it converts their input to lowercase and compares so it's easier to find a filename. I'm assuming that converting the filename to lowercase is why it cannot find the file. For whatever reason, this worked fine in php 4.2. Edit: After testing that theory, when I removed the conversion to lowercase, it fixed everything. Thank you for guiding me in the right direction! Quote Link to comment https://forums.phpfreaks.com/topic/203996-filesize-error-worked-in-php-42-not-51/#findComment-1068449 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.