[PHP-DEV] PHP 4.0 Bug #9499: move() function needed. From: jjgignac <email protected>
Date: 02/28/01

From: jjgignac <email protected>
Operating system: Linux
PHP version: 4.0.4pl1
PHP Bug Type: Filesystem function related
Bug description: move() function needed.

We need a move() function that works across filesystems. I don't care if it's thread-safe. Rename() on my system used to do this until version 4.04pl1. Now my scipts are broken. (I'm sure I'm not the only one.)

This should work for the simplest case (where both $src and $dest are regular files):

function move($src, $dest)
{
    $srcstat = stat($src);
    $deststat = stat(dirname($dest));

    if($srcstat[1] == $deststat[1]) {
        $rc = rename($src, $dest);
    } else {
        $rc = copy($src, $dest);
        if($rc) {
            $rc = (unlink($src) == 0);
            if( !$rc) unlink( $dest);
        }
    }
    return $rc;
}

-- 
Edit Bug report at: http://bugs.php.net/?id=9499&edit=1

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>