Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass db variable to opendir

Status
Not open for further replies.
Jan 8, 2002
23
US
I am having trouble taking a variable obtained from SQL2000, and using it as part of the directory path for an opendir() statement.

Here is the code:
while(odbc_fetch_row($cmservicelistr))
{
$cmnumber = odbc_result($cmservicelistr, 1);
$medreccountq = "select count([logmemo]) from caselogdata where (([clogcase] = $cmnumber) and (medreclink is not null))";
$medreccountr = odbc_exec($connect, $medreccountq);
$medreccount[$lt][0] = odbc_result($medreccountr,1);
$medreccount[$lt][1] = $cmnumber;

/////////////////////////////////////////////////////////
//Check to see how may CM files are in the File Directory
/////////////////////////////////////////////////////////
// $dirsearch = "cm/" . intval($cmnumber) . "/";
// $dirsearch = "cm/" . strval($cmnumber) . "/";
// $dirsearch = "cm/" . $cmnumber . "/";
// $dirsearch = "cm/$cmnumber/";
// $dirsearch = ("cm/" . $medreccount[$lt][1] . "/");
$dirsearch = ("cm/" . 41659 . "/");
echo $cmnumber . "   ";
//Identify files in PATH provided by $dirsearch
$dh = opendir($dirsearch);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;}

//Track number of files per CM#
$filescountarray[] = count($files)-2;
unset($files);
$lt++;
}

The code as shown here works. I have a loop. It gets each CM# in a query (not shown) by "$cmnumber = odbc_result($cmservicelistr, 1);" Then I take each CM# in the loop, and use it as part of a directory path to total the number of files in the directory with "$filescountarray[] = count($files)-2;".

The problem is how I take the CM# and use it as part of the directory path, as in "$dh = opendir($dirsearch);". The current code use for $dirsearch = '$dirsearch = ("cm/" . 41659 . "/");' works because I plug in 41659 (one of the CM#'s). But if I use one of the other "$dirsearch =" lines to incorporate the $cmnumber variable, it fails. Yet the line 'echo $cmnumber . "   ";' prints each cmnumber correctly. And the lines earlier that use $cmnumber, such as "$medreccountq = ..." and "$medreccount[$lt][1] = $cmnumber;" work fine. Why does $cmnumber work fine for the other statements, but not opendir()?

The error I get is not even a statement telling me which line has the error, like a typical PHP error. I either get the "Page can not be displayed" HTTP error. Or I get the "Internet Explorer cannot open the Internet site then below "The server returned an invalid or unrecognized response." In the IIS log, the IIS server issues a status of 200 by each request of this page, not indicating a problem at that end.

I installed SQL 2000 on a separate W2K Server box and installed PHP using PHP.EXE to parse .PHP extensions, to see if the error would go away on a different machine, but it does not.

Is this a PHP coding error?

Thanks,

Jon
 
Have you echoed out:
Code:
    $dirsearch = "cm/" . intval($cmnumber) . "/";
    $dirsearch = "cm/" . strval($cmnumber) . "/";
    $dirsearch = "cm/" . $cmnumber . "/";
    $dirsearch = "cm/$cmnumber/";
This has probably absolutely nothing to do with opendir() but the way you construct the path variable. Let's see what the echo's show.
 
It may also have something to do with the fact that opendir() is not constrained to the current web site's document root. PHP's filesystem functions operate on the server's entire filesystem.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks for the responses.

I just found out what it was. I am working on this alone, and sometimes just bouncing ideas/questions of others and getting their responses seems to get you to think on the right track. I thought I had taken care of this possibility yesterday when I keyed in different values for $dirsearch, as in...

'$dirsearch = ("cm/20555/");'

It was not working for the simple fact that a directory did not exist for one of the numbers!!!!!! You probably wonder how I could not have checked that before... but I already had gone through that yesterday.

True, I knew one of the directories was missing, but I was changing values for $dirsearch, putting in paths I knew didn't exist, and I was getting counts for the files in the root of the virtual directory -- or at least that was the process I had in my head. I know I was getting counts for the files in the root of the virtual directory. I am trying to follow my footsteps to see how I got the counts for the files in the root directory, but now I can't seem to recreate how I did that!

Sorry,

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top