This is the only solution that works and is portable on 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 move correctly, for example:
O:\RECYCLER\S-1-5-21-1715567821-1390067357-1417001333-1003
Recovering from the trash should be possible, but I have not tested it.
EDIT . I just updated this function to work with files that have relative paths.
source
share