PHP is_readable returns false after odbc connection is established

75 views Asked by At
<?php
echo get_current_user();
$file_path = "templates\index.tpl";
$test = getcwd() . "\\".        $file_path;
echo $test."\r\n";

if(is_readable($test)) {
echo ("Readable!\r\n");
} else {
echo ("Not readable!\r\n");
}

odbc_connect("kontaktdb", null, null);
?>

Returns "Readable!"

<?php
echo get_current_user();
$file_path = "templates\index.tpl";
$test = getcwd() . "\\".        $file_path;
echo $test."\r\n";

odbc_connect("kontaktdb", null, null);

if(is_readable($test)) {
echo ("Readable!\r\n");
} else {
echo ("Not readable!\r\n");
}
?>

Returns "Not readable!"

So when is_readable is called after the ODBC Connection is made, it fails - nothing else has changed.

Windows Server 2012 + IIS + PHP 5.4.45

I have absolute no idea what's the cause of it. Any ideas?

1

There are 1 answers

0
YurongDai On

Based on the code you provided, the reason for this difference in output is that establishing an ODBC connection can lock the file and prevent other processes from accessing it. In the first code block, the file is not locked because the ODBC connection has not been established. But in the second code block, the ODBC connection is established before the file is checked for readability, so the file is locked and false is returned. So close the ODBC connection before checking the readability of the file and you will be able to read the file normally.