Пример #1
0
 /**
  * Move file to the other path.
  *
  * @access     public
  * @param    string $sPath
  * @return    File
  * @since      2.36.4-dev, 2015-07-03
  * @version    2.37.0-dev, 2015-07-28
  */
 public function moveFile($sPath)
 {
     \FileManager::prepareDir($sPath);
     $oFileManager = new \FileManager();
     $oFileManager->prepareFileByPath($this->getPath() . '/' . $this->getNameWithExt());
     $oFileManager->move($sPath);
     $this->setName($oFileManager->getName());
     // if file name was changed in \FileManager class
     $this->setPath($oFileManager->getPath());
     return $this;
 }
Пример #2
0
    $list = array_map(function ($item) {
        $date = new \DateTime('now');
        $item['date'] = $date->format('Y-m-d H:i:s');
        return $item;
    }, $list);
    $oResponse->setData($list);
    $oResponse->flushJson();
}
if (Request::getApiParam('mode') === 'editfile') {
    $oResponse->setData($oFtp->getContent(Request::getApiParam('path')));
    $oResponse->flushJson();
}
if (Request::getApiParam('mode') === 'rename') {
    $path = Request::getApiParam('path');
    $newPath = Request::getApiParam('newPath');
    $result = $oFtp->move($path, $newPath);
    if (!$result) {
        throw new Exception("Unknown error renaming this folder");
    }
    $oResponse->setData($result);
    $oResponse->flushJson();
}
if (Request::getApiParam('mode') === 'delete') {
    $path = Request::getApiParam('path');
    $result = $oFtp->delete($path);
    if (!$result) {
        throw new Exception("Unknown error removing this item");
    }
    $oResponse->setData($result);
    $oResponse->flushJson();
}
Пример #3
0
     }
 }
 if (api_is_coach()) {
     if (!DocumentManager::is_visible_by_id($_POST['move_file'], $_course, api_get_session_id(), api_get_user_id())) {
         api_not_allowed();
     }
 }
 $document_to_move = DocumentManager::get_document_data_by_id($_POST['move_file'], api_get_course_id());
 // Security fix: make sure they can't move files that are not in the document table
 if (!empty($document_to_move)) {
     $real_path_target = $base_work_dir . $_POST['move_to'] . '/' . basename($document_to_move['path']);
     $fileExist = false;
     if (file_exists($real_path_target)) {
         $fileExist = true;
     }
     if (FileManager::move($base_work_dir . $document_to_move['path'], $base_work_dir . $_POST['move_to'])) {
         //if (1) {
         //$contents = DocumentManager::replace_urls_inside_content_html_when_moving_file(basename($document_to_move['path']), $base_work_dir.dirname($document_to_move['path']), $base_work_dir.$_POST['move_to']);
         //exit;
         FileManager::update_db_info('update', $document_to_move['path'], $_POST['move_to'] . '/' . basename($document_to_move['path']));
         //update database item property
         $doc_id = $_POST['move_file'];
         if (is_dir($real_path_target)) {
             api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderMoved', api_get_user_id(), $to_group_id, null, null, null, $session_id);
             Display::display_confirmation_message(get_lang('DirMv'));
         } elseif (is_file($real_path_target)) {
             api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'DocumentMoved', api_get_user_id(), $to_group_id, null, null, null, $session_id);
             Display::display_confirmation_message(get_lang('DocMv'));
         }
         // Set the current path
         $curdirpath = $_POST['move_to'];
Пример #4
0
 function test_move()
 {
     FileManager::touch('move_test.txt');
     $this->assertTrue(file_exists('files/move_test.txt'));
     $res = FileManager::move('move_test.txt', 'design');
     $this->assertTrue($res);
     $this->assertFalse(file_exists('files/move_test.txt'));
     $this->assertTrue(file_exists('files/design/move_test.txt'));
     $res = FileManager::move('design/move_test.txt', '..');
     $this->assertFalse($res);
     $this->assertEquals('Invalid folder', FileManager::error());
     $res = FileManager::move('design/move_test.txt', '');
     $this->assertTrue($res);
     $this->assertTrue(file_exists('files/move_test.txt'));
     $this->assertFalse(file_exists('files/design/move_test.txt'));
     FileManager::unlink('move_test.txt');
 }
    $list = array_map(function ($item) {
        $date = new \DateTime('now');
        $item['date'] = $date->format('Y-m-d H:i:s');
        return $item;
    }, $list);
    $oResponse->setData($list);
    $oResponse->flushJson();
}
if (Request::getApiParam('action') === 'getContent') {
    $oResponse->setData($oFtp->getContent(Request::getApiParam('item')));
    $oResponse->flushJson();
}
if (Request::getApiParam('action') === 'rename') {
    $item = Request::getApiParam('item');
    $newItemPath = Request::getApiParam('newItemPath');
    $result = $oFtp->move($item, $newItemPath);
    if (!$result) {
        throw new Exception("Unknown error renaming this item");
    }
    $oResponse->setData($result);
    $oResponse->flushJson();
}
if (Request::getApiParam('action') === 'move') {
    $items = Request::getApiParam('items');
    $newPath = Request::getApiParam('newPath');
    $errors = array();
    foreach ($items as $item) {
        $fileName = explode('/', $item);
        $fileName = end($fileName);
        $finalPath = $newPath . '/' . $fileName;
        $result = $item ? $oFtp->move($item, $finalPath) : false;