protected function elFinderVolumeDrupal::_move in elFinder file manager 6.2
Same name and namespace in other branches
- 8.2 src/Controller/elFinderVolumeDrupal.php \elFinderVolumeDrupal::_move()
- 7.3 inc/elfinder.drupalfs.driver.inc \elFinderVolumeDrupal::_move()
- 7.2 inc/elfinder.drupalfs.driver.inc \elFinderVolumeDrupal::_move()
* Move file into another parent dir * *
Parameters
string $source source file path: * @param string $target target dir path * @param string $name file name * @return bool * @author Alexey Sukhotin *
File
- inc/
elfinder.drupalfs.driver.inc, line 165
Class
- elFinderVolumeDrupal
- elFinder driver for Drupal 6 filesystem.
Code
protected function _move($source, $targetDir, $name) {
$target = $targetDir . DIRECTORY_SEPARATOR . (!empty($name) ? $name : basename($source));
if (!$this
->CheckExtension($this
->_drupalfileobject($target))) {
return FALSE;
}
if (is_dir($source)) {
$sourceDir = dirname($source);
$dstpath = $this
->_relpathdrupal($target);
$srcpath = $this
->_relpathdrupal($source);
$result = db_query("SELECT * FROM {files} f WHERE f.filepath LIKE '%s/%%'", $srcpath);
$done = FALSE;
$rows = array();
while ($row = db_fetch_object($result)) {
$rows[] = $row;
}
foreach ($rows as $row) {
$newpath = str_replace("{$srcpath}/", "{$dstpath}/", $row->filepath);
$result = db_query("UPDATE {files} SET filepath = '%s' WHERE fid = '%d'", $newpath, $row->fid);
}
return @rename($source, $target);
}
else {
$sourceDir = dirname($source);
$sourceFile = $this
->_drupalfileobject($source);
$destFile = $sourceFile;
if ($sourceFile->filename != $name && $name != '') {
$destFile->filename = $name;
}
$destFile->filepath = $this
->_relpathdrupal($targetDir) . DIRECTORY_SEPARATOR . $destFile->filename;
if ($sourceDir == $targetDir) {
if (!rename($source, $target)) {
return FALSE;
}
}
else {
if (!file_move($source, $targetDir)) {
return FALSE;
}
}
if (drupal_write_record('files', $destFile, array(
'fid',
))) {
return TRUE;
}
}
return FALSE;
}