示例#1
0
 /**
  * Write data from request into a file
  *
  * @param \PEAR2\HTTP\Request\Response $response Response to get data
  *
  * @return string
  */
 protected function writeDataToFile(\PEAR2\HTTP\Request\Response $response)
 {
     if (!\Includes\Utils\FileManager::isDir(LC_DIR_TMP)) {
         \Includes\Utils\FileManager::mkdir(LC_DIR_TMP);
     }
     if (!\Includes\Utils\FileManager::isDirWriteable(LC_DIR_TMP)) {
         \Includes\ErrorHandler::fireError('Directory "' . LC_DIR_TMP . '" is not writeable');
     }
     $path = \Includes\Utils\FileManager::getUniquePath(LC_DIR_TMP, uniqid() . '.' . \Includes\Utils\PHARManager::getExtension() ?: 'tar');
     return isset($response->body) && \Includes\Utils\FileManager::write($path, $response->body) ? $path : null;
 }
示例#2
0
 /**
  * "Local file" handler for category images.
  * Returns path of the temporary file
  *
  * @return void
  */
 protected function doActionSelectLocalLanguageFile()
 {
     $result = null;
     $path = \XLite\View\BrowseServer::getNormalizedPath(\XLite\Core\Request::getInstance()->local_server_file);
     $tmpPath = \Includes\Utils\FileManager::getUniquePath(LC_DIR_TMP, basename($path));
     if (copy($path, $tmpPath)) {
         $result = $tmpPath;
     }
     $this->doActionSelectLanguageFile($result);
 }
示例#3
0
 /**
  * Import action
  *
  * @return void
  */
 protected function doActionImport()
 {
     foreach (\XLite\Logic\Import\Importer::getImportOptionsList() as $key) {
         \XLite\Core\Database::getRepo('XLite\\Model\\Config')->createOption(array('category' => 'Import', 'name' => $key, 'value' => isset(\XLite\Core\Request::getInstance()->options[$key]) ? \XLite\Core\Request::getInstance()->options[$key] : false));
     }
     \XLite\Core\Config::updateInstance();
     $dirTo = LC_DIR_VAR . \XLite\Logic\Import\Importer::getImportDir();
     if (!\Includes\Utils\FileManager::isExists($dirTo)) {
         \Includes\Utils\FileManager::mkdirRecursive($dirTo);
     }
     $filesToImport = array();
     if ($_FILES && isset($_FILES['files']) && $_FILES['files']['name'] && $_FILES['files']['name'][0] && \Includes\Utils\FileManager::isDirWriteable($dirTo)) {
         $list = glob($dirTo . LC_DS . '*');
         if ($list) {
             foreach ($list as $path) {
                 if (is_file($path)) {
                     \Includes\Utils\FileManager::deleteFile($path);
                 }
             }
         }
         $files = $_FILES['files'];
         foreach ($files['name'] as $key => $name) {
             $path = null;
             if ($name && UPLOAD_ERR_OK === $files['error'][$key]) {
                 $path = \Includes\Utils\FileManager::getUniquePath($dirTo, $name ?: $files['name'][$key]);
                 if (move_uploaded_file($files['tmp_name'][$key], $path)) {
                     if (\XLite\Core\Archive::getInstance()->isArchive($path) || 'csv' == substr(strrchr($path, '.'), 1)) {
                         $filesToImport[] = $path;
                     } else {
                         \XLite\Core\TopMessage::addError('The "{{file}}" is not CSV or archive', array('file' => $name));
                         \Includes\Utils\FileManager::deleteFile($path);
                     }
                 } else {
                     $path = null;
                 }
             }
             if (!$path) {
                 \XLite\Core\TopMessage::addError('The "{{file}}" file was not uploaded', array('file' => $name));
             }
         }
     }
     if ($filesToImport) {
         \XLite\Logic\Import\Importer::run(\XLite\Logic\Import\Importer::assembleImportOptions() + array('files' => $filesToImport));
     }
 }
示例#4
0
 /**
  * Load from local file
  *
  * @param string $path     Absolute path
  * @param string $basename File name OPTIONAL
  *
  * @return boolean
  */
 public function loadFromLocalFile($path, $basename = null)
 {
     $result = true;
     $basename = $basename ?: basename($path);
     if (\Includes\Utils\FileManager::isExists($path)) {
         foreach ($this->getAllowedFileSystemRoots() as $root) {
             if (\Includes\Utils\FileManager::getRelativePath($path, $root)) {
                 $local = true;
                 break;
             }
         }
         if (empty($local)) {
             $newPath = \Includes\Utils\FileManager::getUniquePath($this->getStoreFileSystemRoot(), $basename);
             if (\Includes\Utils\FileManager::copy($path, $newPath)) {
                 $path = $newPath;
                 $this->setStorageType(static::STORAGE_RELATIVE);
             } else {
                 \XLite\Logger::getInstance()->log('\'' . $path . '\' file could not be copied to a new location \'' . $newPath . '\'.', LOG_ERR);
                 $result = false;
             }
         } else {
             $this->setStorageType(static::STORAGE_ABSOLUTE);
         }
     } else {
         $result = false;
     }
     if ($result && $basename) {
         $this->setFileName($basename);
     }
     return $result && $this->savePath($path);
 }
示例#5
0
 /**
  * Update file path - change file extension taken from MIME information.
  *
  * @return boolean
  */
 protected function updatePathByMIME()
 {
     $result = parent::updatePathByMIME();
     if ($result && !$this->isURL()) {
         list($path, ) = $this->getLocalPath();
         $newExtension = $this->getExtensionByMIME();
         $pathinfo = pathinfo($path);
         if ($newExtension !== $pathinfo['extension']) {
             $newPath = \Includes\Utils\FileManager::getUniquePath($pathinfo['dirname'], $pathinfo['filename'] . '.' . $newExtension);
             $result = rename($path, $newPath);
             if ($result) {
                 $this->path = basename($newPath);
             }
         }
     }
     return $result;
 }
示例#6
0
 /**
  * Load import file from URL 
  * 
  * @param string $url URL
  *  
  * @return string
  */
 protected function loadFromURLImport($url)
 {
     $result = null;
     $content = \XLite\Core\Operator::getURLContent($url);
     $path = \Includes\Utils\FileManager::getUniquePath(LC_DIR_TMP, basename($path));
     if ($content && file_put_contents($path, $content)) {
         $result = $path;
     }
     return $result;
 }