Hi,
This question is related to a Windows install of PHP5.
Doing a file unlink()
makes it difficult for recovery.
Instead I would like to move the file to the Recycle Bin (without doing an exec()
).
Do you have any idea?
Thanks for your help.
Hi,
This question is related to a Windows install of PHP5.
Doing a file unlink()
makes it difficult for recovery.
Instead I would like to move the file to the Recycle Bin (without doing an exec()
).
Do you have any idea?
Thanks for your help.
why dont you just create one folder and name it "Recycle Bin" .. then instead of doing an unlink() .. just move the files to this "Recycle Bin" folder??
If you wish to move a file, use the rename() php function.
Then later you can run a cron script which checks the time of the files and then you can delete files, say, older than 10 days etc.
I hope this helps.
This is the only solution that works and it's portable in all drives.
function Recycle($filename)
{
if (is_file($filename) === true)
{
$filename = realpath($filename);
$recycle = glob(current(explode('\\', $filename, 2)) . '\\RECYCLER\\*', GLOB_ONLYDIR);
if (is_array($recycle) === true)
{
return rename($filename, current($recycle) '\\' . basename($filename));
}
}
return false;
}
Deleted files are correctly moved to for instance:
O:\RECYCLER\S-1-5-21-1715567821-1390067357-1417001333-1003
Restore from the Recycle Bin should be possible, however I've not tested it.
EDIT: I just updated this function to work with files that have relative paths.