开发者

php fopen returns false but file is readable/writable

开发者 https://www.devze.com 2023-01-15 12:18 出处:网络
have a file that is readable and writable but fopen is returning false... if(is_readable($file)) echo \'readable \';

have a file that is readable and writable but fopen is returning false...

if(is_readable($file)) echo 'readable ';
if(is_writable($file)) echo 'writable ';
$fp = fopen($file, 'a+');
var_dump($fp);

result is

readable writable bool(false)

Any ideas?

sure it must 开发者_如何学Gobe a permission thing but tried 777 on the file with same results.


Let's try to get more information.
What does

$file = 'p:\muh';

error_reporting(E_ALL);
ini_set('display_errors', true);
echo 'phpversion: ', phpversion(), "\n";
echo 'uname: ', php_uname("s r"), "\n"; // name/release of the operating system
echo 'sapi: ', php_sapi(), "\n";

echo $file, file_exists($file) ? ' exists' : ' does not exist', "\n";
echo $file, is_readable($file) ? ' is readable' : ' is NOT readable', "\n";
echo $file, is_writable($file) ? ' is writable' : ' is NOT writable', "\n";

$fp = fopen($file, 'a+');
if ( !$fp ) {
  echo 'last error: ';
  var_dump(error_get_last());
}
else {
  echo "ok.\n";
}

print?

see also: http://docs.php.net/error_get_last


I had the same problem. In my case, it was as simple as making sure the file is:

C:\route\to\file\filename.EXTENSION

In my case I was just missing the .PDF extension, so it was interpreting the name of the file as another subdirectory.

0

精彩评论

暂无评论...
验证码 换一张
取 消