i have this following php code :
$filename = '/front/style.css';
$cssfile='#h1{font-size:12px}';
if($id_file=fopen($filename, "w+"))
{
echo'file exist';
$id_file=fopen($filename, "w+");
flock($id_file,1);
fwrite($id_file,$cssfile);
flock($id_file,3);
fclose($id_file);
}
else
{
echo "file don t exist";
}
My file is empty but with space.
My file exist and it s writable.
I have nothing in my apache logs.
I m using Mamp with php 5.3.2.
Any ideas ?
Thx
A few mistakes I can see are:
You are using
fopento check if a file exists. That does not work. With thew+mode PHP will try to create the file if it does not exist. Use thefile_exitsfunction to check the existence of a file.You are opening the same file twice.
Also use PHP constants(
LOCK_SH,LOCK_UN) for the second argument offlock. That will make your program more readable.