Jump to content

My File Isn't Found


jp2php

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.