这是一个非常奇怪的问题。
$file = '/home/wwwroot/website/web/modules/homegrid/css/bootstrap-carousel.min.css';
clearstatcache();
var_dump(file_exists($file));//output true
var_dump(is_file($file));//output true
var_dump(is_dir($file));//output false
var_dump(is_readable($file));//output true
var_dump(is_writable($file));//output true
var_dump(fopen($file, 'w+'));//output false
var_dump(file_put_contents($file, 'asdfasdf'));//output false
fopen和file_put_contents总是为false,但文件存在。 在php 5.6和php-fpm
中答案 0 :(得分:2)
8小时后我终于找到了解决方案,但仍然不知道为什么。
if(file_exists($file))
{
unlink($file);
touch($file);
}
var_dump(fopen($file, 'w+'));//output resource
它就像阻止文件写入的东西一样,我从未听说过php有任何文件阻塞的东西。
答案 1 :(得分:1)
嗨,请尝试检查上一个错误
$fp = fopen($file, 'w+');
if ( !$fp ) {
echo 'last error: ';
var_dump(error_get_last());
}
else {
echo "ok.\n";
}
答案 2 :(得分:0)
ActionBar
将<?php
$myfile = fopen($file, "r+") or die("Unable to open file!");
$txt = "asdfasdf";
fwrite($myfile, $txt);
fclose($myfile);
ob_end_clean();
?>
更改为此(fopen($file, 'w+'));
。
文件权限