foxclone Posted March 31, 2021 Share Posted March 31, 2021 I'm trying to get the filesize() of a file based on a retrieval of filename from the database. The file is located in the download directory and the code calling the function is in the root of the website. Here's the code I've tried: $test = $pdo->query("SELECT filename FROM files WHERE id =1"); $isoname = $test->fetchColumn(); $test = "download/".$isoname; $isosize = filesize($test)/1000000; It always returns zero although is returns the correct filename. Thanks for any guidance in advance. Quote Link to comment https://forums.phpfreaks.com/topic/312407-help-using-filesize-function/ Share on other sites More sharing options...
gw1500se Posted March 31, 2021 Share Posted March 31, 2021 I'm guessing there is a problem with the path. Make sure you have error reporting turned on. error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/312407-help-using-filesize-function/#findComment-1585547 Share on other sites More sharing options...
MadTechie Posted April 10, 2021 Share Posted April 10, 2021 gw1500se is probably correct here, Quick update $test = $pdo->query("SELECT filename FROM files WHERE id =1"); $isoname = $test->fetchColumn(); $test = "download/".$isoname; if(!file_exists($test)) die("File missing:".$test); //<--added for testing $isosize = filesize($test)/1000000; Might be a path update like $test = __DIR__."/download/".$isoname; Quote Link to comment https://forums.phpfreaks.com/topic/312407-help-using-filesize-function/#findComment-1585701 Share on other sites More sharing options...
dodgeitorelse3 Posted April 10, 2021 Share Posted April 10, 2021 is the filename from files table stored with file extension? Quote Link to comment https://forums.phpfreaks.com/topic/312407-help-using-filesize-function/#findComment-1585703 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.