Ejemplo n.º 1
0
 /**
  * Envoi une image sur le serveur avec la méthode upload
  * @param files $img
  * @param dir $path
  * @param bool $setOption
  * @param bool|\debug $debug $debug
  * @return null|string|\true
  */
 public static function uploadImg($img, $path, $setOption = false, $debug = false)
 {
     $error = null;
     $makefile = new filesystem_makefile();
     $firebug = new debug_firephp();
     if (is_array($setOption)) {
         if (array_key_exists('maxwidth', $setOption)) {
             $maxwidth = $setOption['maxwidth'];
         } else {
             $maxwidth = 2500;
         }
         if (array_key_exists('maxheight', $setOption)) {
             $maxheight = $setOption['maxheight'];
         } else {
             $maxheight = 2500;
         }
         if (array_key_exists('minheight', $setOption)) {
             $minheight = $setOption['minheight'];
         } else {
             $minheight = 5;
         }
         if (array_key_exists('minwidth', $setOption)) {
             $minwidth = $setOption['minwidth'];
         } else {
             $minwidth = 5;
         }
     } else {
         $maxwidth = 2500;
         $maxheight = 2500;
         $minheight = 5;
         $minwidth = 5;
     }
     /**
      * Envoi de l'image
      */
     if (isset($_FILES[$img])) {
         if ($_FILES[$img]['error'] == UPLOAD_ERR_OK) {
             if (self::imageValid($_FILES[$img]['tmp_name']) === false) {
                 $error .= 'Invalid image format (gif, png, jpeg only)';
             } else {
                 if (!is_readable($_FILES[$img]["tmp_name"])) {
                     //$tmp_img = chmod($_FILES[$img]["tmp_name"],0777);
                     $tmp_img = $makefile->chmod(array($_FILES[$img]["tmp_name"]), 0777);
                 } else {
                     $tmp_img = $_FILES[$img]["tmp_name"];
                 }
                 //if(chmod($_FILES[$img]["tmp_name"],0777)){
                 if (is_uploaded_file($_FILES[$img]["tmp_name"])) {
                     $source = $tmp_img;
                     $cible = component_core_system::basePath() . $path . '/' . http_url::clean($_FILES[$img]["name"]);
                     if (self::imgSizeMax($source, $maxwidth, $maxheight) == false) {
                         $error .= 'Exceeds the maximum size ' . $maxwidth . ' x ' . $maxheight;
                     } elseif (self::imgSizeMin($source, $minwidth, $minheight) == false) {
                         $error .= 'The file is too small: ' . $minwidth . ' x ' . $minheight;
                     } else {
                         if (!move_uploaded_file($source, $cible)) {
                             $error .= 'Error in temporary file';
                         } else {
                             if ($debug != false) {
                                 $firebug->group('Upload image infos');
                                 $firebug->log('Success', 'Status');
                                 $firebug->log($source, 'Source');
                                 $firebug->log($cible, 'Cible');
                                 $firebug->groupEnd();
                             }
                         }
                     }
                 } else {
                     $error .= 'Disk write error';
                 }
                 //}
             }
         } elseif (UPLOAD_ERR_INI_SIZE == true) {
             $error .= 'The file is too large';
         } elseif (UPLOAD_ERR_CANT_WRITE == true) {
             $error .= 'Disk write error';
         } elseif (UPLOAD_ERR_FORM_SIZE == true) {
             $error .= 'The file is too large: maximum size ' . $maxwidth . ' x ' . $maxheight;
         }
     } elseif (UPLOAD_ERR_NO_FILE == true) {
         $error .= 'No file';
     } else {
         $error .= 'Disk write error';
     }
     if ($error != null) {
         $n = $firebug->group('Upload image analyse');
         $n .= $firebug->log($error);
         $n .= $firebug->groupEnd();
     } else {
         $n = NULL;
     }
     return $n;
 }
Ejemplo n.º 2
0
 /**
  * Retourne le chemin vers un fichier de log déterminé à partir des paramètres $type, $name et $archive.
  * (ex: /Applications/MAMP/www/monsite/logs/erreurs/201202/201202_erreur_connexion.log)
  * Elle crée le chemin s'il n'existe pas.
  *
  * @param string $type Dossier dans lequel sera enregistré le fichier de log
  * @param string $name Nom du fichier de log
  * @param string $archive Archivage : LOG_VOID, LOG_MONTH ou LOG_YEAR
  * @return string Chemin vers le fichier de log
  **/
 private function path($type, $name, $archive = self::LOG_YEAR)
 {
     # On vérifie que le logger est prêt (et donc que le dossier de dépôt existe)
     if (!$this->ready) {
         trigger_error("Logger is not ready", E_USER_WARNING);
         return false;
     }
     # Contrôle des arguments
     if (!isset($type) || empty($name)) {
         trigger_error("Paramètres incorrects", E_USER_WARNING);
         return false;
     }
     $makefile = new filesystem_makefile();
     # Création dossier du type (ex: /Applications/MAMP/www/monsite/logs/erreurs/)
     if (empty($type)) {
         $type_path = $this->pathlog . '/';
     } else {
         $type_path = $this->pathlog . '/' . $type . '/';
         if (!is_dir($type_path)) {
             $makefile->mkdir(array($type_path));
         }
     }
     $date = new date_dateformat();
     # Création du dossier archive (ex: /Applications/MAMP/www/monsite/logs/erreurs/201202/)
     if ($archive == self::LOG_VOID) {
         $logfile = $type_path . $name . '.log';
     } elseif ($archive == self::LOG_MONTH) {
         $current_year = $date->dateDefine('Y');
         $current_month = $date->dateDefine('m');
         $type_path_month = $type_path . $current_year;
         if (!is_dir($type_path_month)) {
             $makefile->mkdir(array($type_path_month));
         }
         $logfile = $type_path_month . '/' . $current_year . $current_month . '_' . $name . '.log';
     } elseif ($archive == self::LOG_YEAR) {
         $current_year = $date->dateDefine('Y');
         $type_path_year = $type_path . $current_year;
         if (!is_dir($type_path_year)) {
             $makefile->mkdir(array($type_path_year));
         }
         $logfile = $type_path_year . '/' . $current_year . '_' . $name . '.log';
     } else {
         trigger_error("LOG Error '{$archive}'", E_USER_WARNING);
         return false;
     }
     return $logfile;
 }