/**
  * @param string $name
  * @param bool $create_subfolders - sign for creating temp folder for backup. set false if only validate
  */
 public function __construct($name, $create_subfolders = true)
 {
     /**
      * @var Registry
      */
     $this->registry = Registry::getInstance();
     //first of all check backup directory create or set writable permissions
     // Before backup process need to call validate() method! (see below)
     if (!make_writable_dir(DIR_BACKUP)) {
         $this->error[] = 'Directory ' . DIR_BACKUP . ' can not be created or is not writable. Backup operation is not possible';
     }
     //Add [date] snapshot to the name and validate if archive is already used.
     //Return error if archive can not be created
     $name = !$name ? 'backup_' . time() : $name;
     $this->backup_name = $name;
     //Create a tmp directory with backup name
     //Create subdirectory /files and  /data
     $this->backup_dir = DIR_BACKUP . $this->backup_name . '/';
     if (!is_dir($this->backup_dir) && $create_subfolders) {
         $result = mkdir($this->backup_dir, 0777, true);
         if (!$result) {
             $error_text = "Error: Can't create directory " . $this->backup_dir . " during backup.";
             $this->log->write($error_text);
             $this->error[] = $error_text;
             $this->backup_dir = $this->backup_name = null;
         }
         chmod($this->backup_dir, 0777);
     }
     if ($this->backup_dir && $create_subfolders) {
         if (!is_dir($this->backup_dir . 'files')) {
             mkdir($this->backup_dir . 'files');
             chmod($this->backup_dir . 'files', 0777);
         }
         if (!is_dir($this->backup_dir . 'data')) {
             mkdir($this->backup_dir . 'data');
             chmod($this->backup_dir . 'data', 0777);
         }
     }
 }
 /**
  * @param string $upload_sub_dir
  * @param string $file_name
  * @return array
  */
 public function getUploadFilePath($upload_sub_dir, $file_name)
 {
     if (empty($file_name)) {
         return array();
     }
     $uplds_dir = DIR_ROOT . '/admin/system/uploads';
     make_writable_dir($uplds_dir);
     $file_path = $uplds_dir . '/' . $upload_sub_dir . '/';
     make_writable_dir($file_path);
     $ext = strrchr($file_name, '.');
     $file_name = substr($file_name, 0, strlen($file_name) - strlen($ext));
     $i = '';
     $real_path = '';
     do {
         if ($i) {
             $new_name = $file_name . '_' . $i . $ext;
         } else {
             $new_name = $file_name . $ext;
             $i = 0;
         }
         $real_path = $file_path . $new_name;
         $i++;
     } while (file_exists($real_path));
     return array('name' => $new_name, 'path' => $real_path);
 }
Beispiel #3
0
 /**
  * @return string
  */
 private function _file_upload_settings_form()
 {
     $this->loadLanguage('catalog/attribute');
     $this->data['form']['settings_fields'] = array('extensions' => $this->html->buildElement(array('type' => 'input', 'name' => 'settings[extensions]', 'value' => $this->data['field_data']['settings']['extensions'], 'style' => 'no-save')), 'min_size' => $this->html->buildElement(array('type' => 'input', 'name' => 'settings[min_size]', 'value' => $this->data['field_data']['settings']['min_size'], 'style' => 'small-field no-save')), 'max_size' => $this->html->buildElement(array('type' => 'input', 'name' => 'settings[max_size]', 'value' => $this->data['field_data']['settings']['max_size'], 'style' => 'small-field no-save')), 'directory' => $this->html->buildElement(array('type' => 'input', 'name' => 'settings[directory]', 'value' => trim($this->data['field_data']['settings']['directory'], '/'), 'style' => 'no-save')));
     $this->data['entry_upload_dir'] = sprintf($this->language->get('entry_upload_dir'), 'admin/system/uploads/');
     $uplds_dir = DIR_APP_SECTION . '/system/uploads';
     $settgs_dir = $uplds_dir . '/' . trim($this->data['attribute_data']['settings']['directory'], '/');
     //check or make writable dirs
     if (!make_writable_dir($uplds_dir) || !make_writable_dir($settgs_dir)) {
         $this->data['form']['settings_fields']['directory'] .= '<i class="error">' . $this->language->get('error_directory_not_writable') . '</i>';
     }
     $this->view->batchAssign($this->data);
     return $this->view->fetch('responses/forms_manager/file_upload_settings.tpl');
 }
 /**
  * Method returns absolute path to temporary directory for unpacking package
  * if system/temp is unaccessable - use php temp directory
  * @return string
  */
 public function getTempDir()
 {
     $tmp_dir = DIR_APP_SECTION . 'system/temp';
     $tmp_install_dir = $tmp_dir . '/install';
     //try to create tmp dir if not yet created and install.
     if (make_writable_dir($tmp_dir) && make_writable_dir($tmp_install_dir)) {
         $dir = $tmp_install_dir . "/";
     } else {
         if (!is_dir(sys_get_temp_dir() . '/abantecart_install')) {
             mkdir(sys_get_temp_dir() . '/abantecart_install/', 0777);
         }
         $dir = sys_get_temp_dir() . '/abantecart_install/';
         if (!is_writable($dir)) {
             $error_text = 'Error: php tried to use directory ' . DIR_APP_SECTION . "system/temp/install" . ' but it is non-writable. Temporary php-directory ' . $dir . ' is non-writable too! Please change permissions one of them.' . "\n";
             $this->error .= $error_text;
             $this->log->write($error_text);
         }
     }
     return $dir;
 }