jp2php Posted July 1, 2009 Share Posted July 1, 2009 I'm trying to verify that my PHP sees my database file before I display information about it: function get_application_filename(){ if ($handle = opendir(getcwd())){ while (false !== ($file = readdir($handle))) { if(strpos($file, "CDT.mdb")){ return $file; } } } return "Not Available"; } I always see the text "Not Available". Am I doing something wrong? The script is located in the same directory as the file. Link to comment https://forums.phpfreaks.com/topic/164405-my-file-isnt-found/ Share on other sites More sharing options...
corbin Posted July 1, 2009 Share Posted July 1, 2009 Have you tried echoing out the variables to see if it should ever match? Link to comment https://forums.phpfreaks.com/topic/164405-my-file-isnt-found/#findComment-867231 Share on other sites More sharing options...
jp2php Posted July 1, 2009 Author Share Posted July 1, 2009 That's a good idea. I'll give it a try and get back with you on the results. Link to comment https://forums.phpfreaks.com/topic/164405-my-file-isnt-found/#findComment-867268 Share on other sites More sharing options...
PFMaBiSmAd Posted July 1, 2009 Share Posted July 1, 2009 You don't need to scan through all the files in a folder to find if a file exists, just use file_exists Link to comment https://forums.phpfreaks.com/topic/164405-my-file-isnt-found/#findComment-867326 Share on other sites More sharing options...
jp2php Posted July 2, 2009 Author Share Posted July 2, 2009 My apologies for the long wait, but this is a moonlighting job, so I have to wait to test the code. The piece I am forced to live with is this: // if ((false !== (strpos($file0, ".mdb"))) && ($db == "")) // THIS VERSION WORKS // if (($file0 == "CDT.mdb") && ($db == "")) // THIS VERSION NEVER FINDS MY FILE // if ((strpos($file0, "CDT.mdb") !== false) && ($db == "")) // THIS VERSION NEVER FINDS MY FILE Here's what I'm using: function dataFile() { $db = ""; echo("<p>" . getcwd() . "</p>"); if ($handle = opendir(getcwd())) { echo("<tr><th>File</th><th>Size</th><th>Date</th></tr>"); while (false !== ($file0 = readdir($handle))) { if (($file0 != ".") && ($file0 != "..")) { echo("<tr><td>"); if ((false !== (strpos($file0, ".mdb"))) && ($db == "")) { echo("<b>" . $file0 . "</b>"); $db = $file0; } else { echo($file0); } echo("</td><td>" . ceil(filesize($file0)/1024) . " kb</td><td>" . date('F j, Y, g:i a', filemtime($file0)) . "</td></tr>"); } } echo("<hr>"); closedir($handle); } if ($db == "") { echo("<br>Database file not found"); } return $db; } function showDownload() { $file1 = dataFile(); echo("<input type=\"hidden\" name=\"Download\" value=\"" . $file1 . "\">"); echo("<table>"); echo("<tr><th>Download</th><th>Date</th><th>Size</th></tr>"); echo("<tr><td>" . $file1 . "</td><td>" . date('F j, Y, g:i a', filemtime($file1)) . "</td><td>" . ceil(filesize($file1)/1024) . "</td></tr>"); echo("</table>"); if ($file1 != "Not Found") { echo("<tr><td> </td><td> </td><td><input type=\"submit\" value=\"OK\" /></td></tr>"); } } This version works, and I can successfully download the file! However, we would eventually like to have more than one file for download, but I can't seem to get PHP to find the file. As an extra note, PFMaBiSmAd, PHP always tells me file_exists() is false, even when it shows up and downloads! Is there something obvious I'm missing? I thought maybe it was the character casing, but the data that is printed on the screen when it finds the file is exactly the string I'm trying to search in the failed function calls. Link to comment https://forums.phpfreaks.com/topic/164405-my-file-isnt-found/#findComment-867743 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.