Beispiel #1
0
 /**
  * Réalise l'upload d'une simple image et retourne son chemin.
  *
  * Par exemple utilisé pour l'upload des filigrane.
  *
  * Il n'y a PAS de création de miniature.
  *
  * @param $form_input_name 		Le nom du champs du formulaire
  * @param $sCurrentImageDir 	Le chemin du répertoire destination
  * @param $sFilename 			Le nom du fichier destination sans l'extension
  * @return string 				Le nom de l'image
  */
 public static function getSingleUploadedFile($form_input_name = 'p_file', $sCurrentImageDir, $sFilename)
 {
     global $okt;
     $return = '';
     if (isset($_FILES[$form_input_name]) && !empty($_FILES[$form_input_name]['tmp_name'])) {
         $sUploadedFile = $_FILES[$form_input_name];
         try {
             # extension du fichier
             $sExtension = pathinfo($sUploadedFile['name'], PATHINFO_EXTENSION);
             # des erreurs d'upload ?
             util::uploadStatus($sUploadedFile);
             # vérification de l'extension
             self::checkExtension($sExtension);
             # vérification du type
             self::checkType($sUploadedFile['type']);
             # création du répertoire s'il existe pas
             if (!file_exists($sCurrentImageDir)) {
                 files::makeDir($sCurrentImageDir, true);
             }
             # nom du fichier
             $sOutput = $sFilename . '.' . $sExtension;
             # suppression de l'éventuel ancien fichier
             if (file_exists($sCurrentImageDir . $sOutput) && files::isDeletable($sCurrentImageDir . $sOutput)) {
                 unlink($sCurrentImageDir . $sOutput);
             }
             if (!move_uploaded_file($sUploadedFile['tmp_name'], $sCurrentImageDir . $sOutput)) {
                 throw new Exception('Impossible de déplacer sur le serveur le fichier téléchargé.');
             }
             $return = $sOutput;
         } catch (Exception $e) {
             $okt->error->set('Problème avec l’image : ' . $e->getMessage());
         }
     }
     return $return;
 }
Beispiel #2
0
 /**
  * Constructor
  *
  * Creates an instance of fileItem object.
  *
  * @param string	$file		Absolute file or directory path
  * @param string	$root		File root path
  * @param string	$root_url		File root URL
  */
 public function __construct($file, $root, $root_url = '')
 {
     $file = path::real($file);
     $stat = stat($file);
     $path = path::info($file);
     $rel = preg_replace('/^' . preg_quote($root, '/') . '\\/?/', '', $file);
     $this->file = $file;
     $this->basename = $path['basename'];
     $this->dir = $path['dirname'];
     $this->relname = $rel;
     $this->file_url = str_replace('%2F', '/', rawurlencode($rel));
     $this->file_url = $root_url . $this->file_url;
     $this->dir_url = dirname($this->file_url);
     $this->extension = $path['extension'];
     $this->mtime = $stat[9];
     $this->size = $stat[7];
     $this->mode = $stat[2];
     $this->uid = $stat[4];
     $this->gid = $stat[5];
     $this->w = is_writable($file);
     $this->d = is_dir($file);
     $this->f = is_file($file);
     $this->x = file_exists($file . '/.');
     $this->del = files::isDeletable($file);
     $this->type = $this->d ? null : files::getMimeType($file);
     $this->type_prefix = preg_replace('/^(.+?)\\/.+$/', '$1', $this->type);
 }
Beispiel #3
0
 function isDeletable()
 {
     return files::isDeletable($this->root . $this->base_path);
 }
Beispiel #4
0
 /**
  * Suppression d'un utilisateur.
  *
  * @param $id
  * @return boolean
  */
 public function deleteUser($id)
 {
     $rsUser = $this->getUsers(array('id' => $id));
     if ($rsUser->isEmpty()) {
         $this->error->set(sprintf(__('m_users_error_user_%s_not_exists'), $id));
         return false;
     }
     # si on veut supprimer un super-admin alors il faut vérifier qu'il y en as d'autres
     if ($rsUser->group_id == oktAuth::superadmin_group_id) {
         $iCountSudo = $this->getUsers(array('group_id' => oktAuth::superadmin_group_id), true);
         if ($iCountSudo < 2) {
             $this->error->set(__('m_users_error_cannot_remove_last_super_administrator'));
             return false;
         }
     }
     # si on veut supprimer un admin alors il faut vérifier qu'il y en as d'autres
     if ($rsUser->group_id == oktAuth::admin_group_id) {
         $iCountAdmin = $this->getUsers(array('group_id' => oktAuth::admin_group_id), true);
         if ($iCountAdmin < 2) {
             $this->error->set(__('m_users_error_cannot_remove_last_administrator'));
             return false;
         }
     }
     $sQuery = 'DELETE FROM ' . $this->t_users . ' ' . 'WHERE id=' . (int) $id;
     if (!$this->db->execute($sQuery)) {
         return false;
     }
     $this->db->optimize($this->t_users);
     # delete user custom fields
     if ($this->config->enable_custom_fields) {
         $this->fields->delUserValue($id);
     }
     # delete user directory
     $user_dir = $this->upload_dir . $id . '/';
     if (files::isDeletable($user_dir)) {
         files::deltree($user_dir);
     }
     return true;
 }
Beispiel #5
0
 /**
  * Modification des fichiers
  *
  * @return array
  */
 public function updFiles($iItemId, $aCurrentFiles = array())
 {
     $aNewFiles = array();
     $j = 1;
     for ($i = 1; $i <= $this->config['number']; $i++) {
         if (!isset($_FILES[sprintf($this->config['files_patern'], $i)]) || empty($_FILES[sprintf($this->config['files_patern'], $i)]['tmp_name'])) {
             if (isset($aCurrentFiles[$i])) {
                 $aNewFiles[$j] = array('filename' => $aCurrentFiles[$i]['filename'], 'title' => !empty($_REQUEST[sprintf($this->config['files_title_patern'], $i)]) ? $_REQUEST[sprintf($this->config['files_title_patern'], $i)] : $aCurrentFiles[$i]['title']);
                 $j++;
             }
             continue;
         }
         $sUploadedFile = $_FILES[sprintf($this->config['files_patern'], $i)];
         try {
             $sExtension = pathinfo($sUploadedFile['name'], PATHINFO_EXTENSION);
             # des erreurs d'upload ?
             util::uploadStatus($sUploadedFile);
             # vérification de l'extension
             $this->checkFile($sExtension);
             # vérification du type
             //				$aAllowedTypes = array('image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png');
             //				if (!in_array($sUploadedFile['type'], $aAllowedTypes)) {
             //					throw new Exception('Type de fichier non-autorisé.');
             //				}
             # création du répertoire s'il existe pas
             if (!file_exists($this->upload_dir)) {
                 files::makeDir($this->upload_dir, true);
             }
             # suppression de l'éventuel ancien fichier
             if (isset($aCurrentFiles[$i]) && files::isDeletable($this->upload_dir . $aCurrentFiles[$i])) {
                 unlink($this->upload_dir . $aCurrentFiles[$i]);
             }
             $sDestination = $this->upload_dir . $iItemId . '-' . $j . '.' . $sExtension;
             if (!move_uploaded_file($sUploadedFile['tmp_name'], $sDestination)) {
                 throw new Exception('Impossible de déplacer sur le serveur le fichier téléchargé.');
             }
             $aNewFiles[$j] = array('filename' => basename($sDestination), 'title' => !empty($_REQUEST[sprintf($this->config['files_title_patern'], $i)]) ? $_REQUEST[sprintf($this->config['files_title_patern'], $i)] : $j);
             $j++;
         } catch (Exception $e) {
             $this->okt->error->set('Problème avec le fichier ' . $i . ' : ' . $e->getMessage());
         }
     }
     return array_filter($aNewFiles);
 }
Beispiel #6
0
 /**
  * Modification des fichiers
  *
  * @return void
  */
 protected function editFiles()
 {
     $aCurrentFiles = $this->getQuestion($this->params['id'])->getFilesInfo();
     $aNewFiles = array();
     foreach ($this->okt->languages->list as $aLanguage) {
         $aNewFiles[$aLanguage['code']] = array();
         $j = 1;
         for ($i = 0; $i <= $this->config->files['number']; $i++) {
             if (!isset($_FILES['p_files_' . $aLanguage['code'] . '_' . $i]) || empty($_FILES['p_files_' . $aLanguage['code'] . '_' . $i]['tmp_name'])) {
                 if (!empty($aCurrentFiles[$aLanguage['code']][$i])) {
                     $aNewFiles[$aLanguage['code']][$i] = $aCurrentFiles[$aLanguage['code']][$i]['filename'];
                     $j++;
                 }
                 continue;
             }
             $sUploadedFile = $_FILES['p_files_' . $aLanguage['code'] . '_' . $i];
             try {
                 # des erreurs d'upload ?
                 util::uploadStatus($sUploadedFile);
                 # vérification de l'extension
                 $sExtension = pathinfo($sUploadedFile['name'], PATHINFO_EXTENSION);
                 if (!in_array($sExtension, explode(',', $this->config->files['allowed_exts']))) {
                     throw new Exception('Type de fichier non-autorisé.');
                 }
                 if (!file_exists($this->upload_dir)) {
                     files::makeDir($this->upload_dir, true);
                 }
                 if (!empty($aCurrentFiles[$aLanguage['code']][$i]) && files::isDeletable($this->upload_dir . $aCurrentFiles[$aLanguage['code']][$i]['filename'])) {
                     unlink($this->upload_dir . $aCurrentFiles[$aLanguage['code']][$i]['filename']);
                 }
                 $sDestination = $this->upload_dir . util::strToLowerURL($this->params['title'][$aLanguage['code']], false) . '-' . $aLanguage['code'] . '-' . $j . '.' . $sExtension;
                 if (!move_uploaded_file($sUploadedFile['tmp_name'], $sDestination)) {
                     throw new Exception('Impossible de déplacer sur le serveur le fichier téléchargé.');
                 }
                 $aNewFiles[$aLanguage['code']][] = basename($sDestination);
                 $j++;
             } catch (Exception $e) {
                 $this->okt->error->set('Pour le fichier ' . $i . ' dans la langue ' . $aLanguage['code'] . ' : ' . $e->getMessage());
             }
         }
     }
     $this->params['files'] = $aNewFiles;
 }