[thelist] Cannot delete csv... so let's edit it?

Phil Turmel pturmel-webdev at turmel.org
Thu Mar 1 07:50:19 CST 2007

Tris wrote:
> Ello all...
> I've got 3 csv files that I'm ftping to a DIR..
> Every 10 mins, they are scanned (along with lots of other functions).
> The contents of the CSV are dumped into a table I've got..
> BUT..
> I want to delete the CSV afterwards..(or the data is duplicated) but
> I'm getting permission denied errors.
> I've CHMODed them, but still no..?
> I've ggogled and there's lots of talk about server persmission, PHP
> permissions etc..
> so, I thought.. why can't I just edit the file(s) on the fly and empty
> them when I'm done?
> Can I edit CSV files in PHP?
> How can I forceably delete a csv?
> Either option is fine by me... any idea?
> Back to google!
> Tris...
Hi Tris,

What you're describing sounds a lot like the "sticky" bit on the FTP
upload directory.  Any file placed there by one user cannot be deleted
or renamed by another.  If the upload user is not the same as the PHP
script user, the script won't be able to delete the file. [1]

A couple possible solutions:

1) after reading in the file, close it, re-open it for write/truncate,
and close again.  Contents would then be wiped. [2]

$fhandle = fopen($filename, "w");

2) note the file modification time when reading, and ignore the file on
future scans if it hasn't changed again. [3]

$fileinfo = stat($filename);
if ($fileinfo['mtime'] != $previousmtime)

Hope this helps,


[1] http://man.cx/chmod(1)#sec5
[2] http://www.php.net/manual/en/function.fopen.php
[3] http://www.php.net/manual/en/function.stat.php

More information about the thelist mailing list