Exemplo n.º 1
0
 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;
 }