Search code examples
phpapachefwritephp-5.5

PHP. Cannot append to the file


Well, I have a problem. On my local LAMP (14.04 LTS 32 bit) all works as magic. Remote server also is Ubuntu 14.04 (64 bit). On the production my program successfully rewrites file:

$myfileresult = fopen('taranko.csv','w+');
echo fwrite($myfileresult,"");
fclose($myfileresult);

but after it my script failed to append any information.

$myfileresult = fopen('download.csv','a');
                fwrite($myfileresult, $ids.";".$imageLinkAlt.";".$itemNameAlt.";".$features.";".$mods[$x].";".$prices[$x].";".$stockQty[$x].PHP_EOL);
                fclose($myfileresult);

I have

ini_set('display_errors', 1);
error_reporting(E_ALL);

in my script, but there are no errors or warnings in PHP echo, indeed. I tried to append this string: "1701-1;http://taranko-shop.ru/.." So, I used strace, this is what I found:

open("/home/ci65797/web/mydomain.com/public_html/download.csv", O_WRONLY|O_CREAT|O_APPEND, 0666) = 24
2056  fstat(24, {st_mode=S_IFREG|0644, st_size=160740, ...}) = 0
2056  lseek(24, 0, SEEK_CUR)            = 0
2056  lseek(24, 0, SEEK_CUR)            = 0
2056  write(24, "1701-1;http://taranko-shop.ru/wa"..., 377) = 377
2056  close(24) 

So, next to the latest string contains my string, which I tried to append. My all directories are 755, the file is 644. What should I do to fix this?


Solution

  • as @Chris suggests, my script just wrote to another file. It happened because I renamed file in the first part of my script and don't renamed in the second.