if ($USER->GetId() && check_bitrix_sessid()) {
     $data = CWebDavIblock::getRootSectionDataForUser($USER->GetID());
     if ($data) {
         $savedFolderId = CIBlockWebdavSocnet::createSavedFolder($data['IBLOCK_ID'], $data['SECTION_ID'], $USER->GetID());
         if ($savedFolderId) {
             $wdElement = $ob->GetObject(array('check_permissions' => false), false);
             //todo hack by load from url with historyget (example)
             if ($wdElement['not_found']) {
                 $partUri = explode('element/historyget/', $ob->uri);
                 if (!empty($partUri[1])) {
                     $elementId = (int) $partUri[1];
                     $wdElement = $ob->GetObject(array('check_permissions' => false, 'element_id' => $elementId), false);
                 }
             }
             if ($ob->CheckWebRights('', array('action' => 'read', 'arElement' => $wdElement), false)) {
                 $storage = new CWebDavStorageCore();
                 $storage->setStorageId(array('IBLOCK_ID' => $data['IBLOCK_ID'], 'IBLOCK_SECTION_ID' => $data['SECTION_ID']));
                 $filename = $storage->regenerateNameIfNonUnique($wdElement['element_name'], $savedFolderId);
                 $tmpFile = new CWebDavStubTmpFile();
                 if ($_REQUEST['v']) {
                     list($arFileH, $optionsH, $fullpath, $filenameH) = $ob->getHistoryFileData($wdElement['element_array']['ID'], (int) $_REQUEST['v'], $p);
                     $tmpFile->path = $fullpath;
                 } else {
                     $copyTmpFile = CFile::MakeFileArray($wdElement['element_array']['PROPERTY_FILE_VALUE']);
                     $tmpFile->path = $copyTmpFile['tmp_name'];
                 }
                 $response = array();
                 try {
                     $fileData = $storage->addFile($filename, $savedFolderId, $tmpFile);
                     $savedName = CWebDavIblock::getSavedMetaData();
                     $pathToUserLib = str_replace(array('#USER_ID#', '#user_id#'), array($USER->GetID(), $USER->GetID()), CWebDavIblock::LibOptions('lib_paths', true, $data['IBLOCK_ID']));
 protected function saveNewFile(array $fileData)
 {
     $filename = CTempFile::GetFileName(uniqid('_wd'));
     CheckDirPath($filename);
     $doc = $this->getDocHandler()->downloadFile(array('id' => $this->getFileId(), 'mimeType' => $this->getWebdav()->get_mime_type('1.' . $fileData['createType'])));
     file_put_contents($filename, $doc['content']);
     global $USER;
     $dataUserSection = CWebDavIblock::getRootSectionDataForUser($USER->GetID());
     if (!$dataUserSection) {
         return array('status' => 'error');
     }
     $createdDocFolderId = CIBlockWebdavSocnet::createCreatedDocFolder($dataUserSection['IBLOCK_ID'], $dataUserSection['SECTION_ID'], $USER->GetID());
     if (!$createdDocFolderId) {
         return array('status' => 'error');
     }
     $storage = new CWebDavStorageCore();
     $storage->setStorageId(array('IBLOCK_ID' => $dataUserSection['IBLOCK_ID'], 'IBLOCK_SECTION_ID' => $dataUserSection['SECTION_ID']));
     $nameToSavedFile = $storage->regenerateNameIfNonUnique($doc['name'], $createdDocFolderId);
     $tmpFile = new CWebDavStubTmpFile();
     $tmpFile->path = $filename;
     try {
         $fileData = $storage->addFile($nameToSavedFile, $createdDocFolderId, $tmpFile);
         $response = array('status' => 'success', 'elementId' => $fileData['extra']['id'], 'sectionId' => $fileData['extra']['sectionId'], 'name' => $nameToSavedFile, 'sizeInt' => $fileData['size'], 'type' => CWebDavBase::get_mime_type($nameToSavedFile), 'link' => str_replace('#element_id#', $fileData['extra']['id'], CWebDavSocNetEvent::getRuntime()->arPath['ELEMENT_EDIT_INLINE_URL']), 'nameWithoutExtension' => GetFileNameWithoutExtension($nameToSavedFile));
     } catch (Exception $e) {
         $response = array('status' => 'error');
     }
     return $response;
 }