elFinder::paste PHP Method

paste() protected method

Copy/move files into new destination
Author: Dmitry (dio) Levashov
protected paste ( $args ) : array
return array
    protected function paste($args)
    {
        $dst = $args['dst'];
        $targets = is_array($args['targets']) ? $args['targets'] : array();
        $cut = !empty($args['cut']);
        $error = $cut ? self::ERROR_MOVE : self::ERROR_COPY;
        $result = array('changed' => array(), 'added' => array(), 'removed' => array());
        if (($dstVolume = $this->volume($dst)) == false) {
            return array('error' => $this->error($error, '#' . $targets[0], self::ERROR_TRGDIR_NOT_FOUND, '#' . $dst));
        }
        $hashes = $renames = array();
        $suffix = '~';
        if (!empty($args['renames'])) {
            $renames = array_flip($args['renames']);
            if (is_string($args['suffix']) && !preg_match('/[\\/\\?*:|"<>]/', $args['suffix'])) {
                $suffix = $args['suffix'];
            }
        }
        if (!empty($args['hashes'])) {
            $hashes = array_flip($args['hashes']);
        }
        foreach ($targets as $target) {
            elFinder::extendTimeLimit();
            if (($srcVolume = $this->volume($target)) == false) {
                $result['warning'] = $this->error($error, '#' . $target, self::ERROR_FILE_NOT_FOUND);
                break;
            }
            $rnres = array();
            if ($renames) {
                $file = $srcVolume->file($target);
                if (isset($renames[$file['name']])) {
                    $dir = $dstVolume->realpath($dst);
                    if (isset($hashes[$file['name']])) {
                        $hash = $hashes[$file['name']];
                    } else {
                        $hash = $dstVolume->getHash($dir, $file['name']);
                    }
                    $rnres = $this->rename(array('target' => $hash, 'name' => $dstVolume->uniqueName($dir, $file['name'], $suffix, true, 0)));
                    if (!empty($rnres['error'])) {
                        $result['warning'] = $rnres['error'];
                        break;
                    }
                }
            }
            if (($file = $dstVolume->paste($srcVolume, $target, $dst, $cut, $hashes)) == false) {
                $result['warning'] = $this->error($dstVolume->error());
                break;
            }
            $dirChange = !empty($file['dirChange']);
            unset($file['dirChange']);
            if ($dirChange) {
                $result['changed'][] = $file;
            } else {
                $result['added'][] = $file;
            }
            if ($rnres) {
                $result = array_merge_recursive($result, $rnres);
            }
        }
        return $result;
    }

Usage Example

コード例 #1
0
ファイル: VisualElFinder.php プロジェクト: florinp/dexonline
 protected function paste($args)
 {
     $result = parent::paste($args);
     $dest = $this->getPath($args['dst']);
     $cut = !empty($args['cut']);
     if ($cut) {
         foreach ($args['targets'] as $target) {
             // If the image has a corresponding Visual, update its .path field and move its thumbnail.
             $path = $this->getPath($target);
             $v = Visual::get_by_path($path);
             if ($v) {
                 $base = basename($path);
                 $v->path = $dest ? "{$dest}/{$base}" : $base;
                 $v->save();
             }
         }
     }
     return $result;
 }