FPDF output from web can't overwrite existing file created from cli

17 Views Asked by At

Took me a while to see what was going on. If I run my script using FPDF it correctly generates and outputs a file to the desired destination:

$this->Output('F',$filePath.$fileName) ;

But when I run the script again it was failing at the same line because it wasn't able to overwrite the previous file (of the same name) because the first time it was created it was somehow write protected. I only discovered this when I manually deleted the file from the folder and saw this:

prompt> rm 12095-S1002_receipt.pdf

rm: remove write-protected regular file '12095-S1002_receipt.pdf'? yes

After I manually deleted the file I was able to run the script again and write a new file of the same name. How is the happening and how can I resolve it?

For background, my scripts are typically run from CLI (via cronjob) and all the files exist as:

-rw-r--r-- 1 root root 23942 Jan 7 03:05 12094-S1001_receipt.pdf

But I have now adapted that same script to also be run from a web interface. The files created from the web interface exist as:

-rw-r--r-- 1 webadmin webadmin 23946 Jan 30 09:17 12095-S1002_receipt.pdf

It appears the files created by root cannot be overwritten by files created by webadmin, but both files have the same permissions. How can I resolve this?

UPDATE:

The folder the files are being created in have permissions:

drwxr-xr-x 2 webadmin webadmin 16384 Jan 30 09:17 invoices

So, the issue appears to be very specific to the fact the a cronjob running as root is creating the original file, which is preventing webadmin from over-writing it.

0

There are 0 best solutions below