linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file class.upload.php

Documentation is available at class.upload.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage system
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  *  Upload management
  10.  */
  11.  
  12. class upload {
  13.   /* @parametres
  14.    * */
  15.   var $FINAL_NAME;
  16.   var $FILE;
  17.   var $DESTINATION;
  18.   var $FTP_SERVER = "localhost";
  19.   var $FTP_USER = "demo_linea";
  20.   var $FTP_PASSWD = "demo_linea";
  21.   var $FTP_MODE = "FTP_BINARY";
  22.   var $FTP_ADMINMAIL = MAIL_LINEA;
  23.   var $TEXT_LENGTH = 5;
  24.   var $TEXT = 5;
  25.   var $IMAGE_TYPE = array("jpeg""jpg""png");
  26.  
  27.   /**
  28.    * upload::CheckMaxFile()
  29.    * Vérifie la taille d'un fichier
  30.    *
  31.    * @access public
  32.    * @param string $file_size : taille du fichier a uploader
  33.    * @param string $max_file : taille de fichier maximale
  34.    * @return bool true si ok sinon message d'erreur (string)
  35.    */
  36.   function CheckMaxFile($file_size$max_file)
  37.   {
  38.     include('../languages/' LANGUAGE '/lang_system.'CHARSET .'.php');
  39.     if ($file_size $max_file{
  40.       $ko_maxfile $max_file 1024;
  41.       return $lang['upload']['upload_size'$ko_maxfile " " $lang['upload']['ko_size'];
  42.     }
  43.     return true;
  44.   }
  45.  
  46.   /**
  47.    * upload::CheckMimeImageType()
  48.    * verifie le type Mime d'une image
  49.    *
  50.    * @access public
  51.    * @param string $dirname : chemin + nom du fichier
  52.    * @return boolean $result
  53.    */
  54.   function CheckMimeImageType($dirname)
  55.   {
  56.     if (function_exists('exif_imagetype')) {
  57.       $exif_type exif_imagetype($dirname);
  58.       if ($exif_type == || $exif_type == || $exif_type == 3return true;
  59.       else unlink($dirname);
  60.     }
  61.     return false;
  62.   }
  63.  
  64.   /**
  65.    * upload::CheckExtImage()
  66.    * Verifie l'extension d'une image
  67.    *
  68.    * @access public
  69.    * @param string $filename : nom du fichier
  70.    * @return string $result
  71.    */
  72.   function CheckExtImage($filename)
  73.   {
  74.     include('../languages/' LANGUAGE '/lang_system.'CHARSET .'.php');
  75.  
  76.     $result $lang['upload']['CheckExtImage'];
  77.  
  78.     $extension $this->GetExtension($filename);
  79.     $ext $this->IMAGE_TYPE;
  80.     for ($i 0;$i count($ext);$i++{
  81.       if ($extension == $ext[$i]return true;
  82.     }
  83.  
  84.     return $result;
  85.   }
  86.  
  87.   /**
  88.    * upload::GetExtension()
  89.    * détermine l'extension d'un fichier
  90.    *
  91.    * @access public
  92.    * @param string $filename : fichier source
  93.    * @return string $extension
  94.    */
  95.   function GetExtension($filename)
  96.   {
  97.     $ext explode('.'$filename);
  98.     $extension $ext[count($ext)-1];
  99.     return $extension;
  100.   }
  101.  
  102.   /**
  103.    * upload::GetName()
  104.    * obtenir le nom d'un fichier, sans son extension
  105.    *
  106.    * @access public
  107.    * @param string $filename : fichier source
  108.    * @return string $name
  109.    */
  110.   function GetName($filename)
  111.   {
  112.     $ext explode('.'$filename);
  113.     $i 0;
  114.     $name '';
  115.     while ($i count($ext)-1{
  116.       $name .= $ext[$i'.';
  117.       $i++;
  118.     }
  119.     return $name;
  120.   }
  121.  
  122.   /**
  123.    * upload::Archivefile()
  124.    * archive un fichier si nécessaire
  125.    *
  126.    * @access public
  127.    * @param  $path 
  128.    * @return void 
  129.    */
  130.   function Archivefile($path)
  131.   {
  132.     $ext $this->IMAGE_TYPE;
  133.     $short_path dirname($path);
  134.     $filename basename($path);
  135.     $temp_path $short_path "/temp_" $filename;
  136.     $shortname $this->GetName($filename);
  137.  
  138.     for($i 0$i count($ext)$i++{
  139.       $current_path $short_path "/" $shortname $ext[$i];
  140.       $current_old_path $short_path "/old_" $shortname $ext[$i];
  141.       $current_temp_path $short_path "/temp_" $shortname $ext[$i];
  142.       if (file_exists($current_temp_path)) {
  143.         if (file_exists($current_old_path)) unlink($current_old_path);
  144.         if (file_exists($current_path)) rename($current_path$current_old_path);
  145.         // gestion des fichiers de miniatures
  146.         if (file_exists(get_min_name($current_old_path))) unlink(get_min_name($current_old_path));
  147.         if (file_exists(get_min_name($current_path))) rename(get_min_name($current_path)get_min_name($current_old_path));
  148.       }
  149.     }
  150.  
  151.     if (file_exists($temp_path)) rename ($temp_path$path);
  152.     if (file_exists(get_min_name($temp_path))) rename (get_min_name($temp_path)get_min_name($path));
  153.     return true;
  154.   }
  155.  
  156.   /**
  157.    * upload::_HTTPUpload()
  158.    * upload un fichier - Protocole HTTP
  159.    *
  160.    * @access private
  161.    * @return boolean : Message d'erreur ou True;
  162.    */
  163.   function _HTTPUpload()
  164.   {
  165.     include('../languages/' LANGUAGE '/lang_system.'CHARSET .'.php');
  166.     $result false;
  167.     if ($this->FILE['name'!= 'none' && $this->FILE['size'!= 0{
  168.       if (file_exists($this->DESTINATION . "/" $this->FINAL_NAME)) unlink ($this->DESTINATION . "/" $this->FINAL_NAME);
  169.       if (!file_exists($this->DESTINATION . "/" $this->FINAL_NAME)) {
  170.         if (!file_exists($this->DESTINATION)) {
  171.           mkdir($this->DESTINATION0755);
  172.         }
  173.         if (move_uploaded_file($this->FILE['tmp_name']$this->DESTINATION . $this->FINAL_NAME)) {
  174.           $result true;
  175.         else {
  176.           $result $lang['upload']['prohibited_transfert'];
  177.         }
  178.       else {
  179.         $result "'" $this->FINAL_NAME . "'" $lang['upload']['file_exist_yet'];
  180.       }
  181.     }
  182.     return $result;
  183.   }
  184.  
  185.   /**
  186.    * upload::_FTPUpload()
  187.    * !!! NON IMPLEMENTE/ NON TESTE !!!
  188.    * upload un fichier - Protocole FTP
  189.    *
  190.    * @access private
  191.    * @return boolean : Message d'erreur ou True;
  192.    */
  193.   function _FTPUpload()
  194.   {
  195.     include('../languages/' LANGUAGE '/lang_system.'CHARSET .'.php');
  196.     $this->DESTINATION = "./" $this->DESTINATION;
  197.     $result false;
  198.     $conn_id @ftp_connect($this->FTP_SERVER);
  199.     $login_result @ftp_login($conn_id$this->FTP_USER$this->FTP_PASSWD);
  200.     if ((!$conn_id|| (!$login_result)) {
  201.       $erreur $lang['upload']['ftp_conn_failed'END_LINE;
  202.       $erreur .= $lang['upload']['ftp_conn'' ' $this->FTP_SERVER . ' ' $lang['upload']['ftp_user'' : ' FTP_USER ;
  203.       if ($this->FTP_ADMINMAIL != -1@error_log ($erreur1$this->FTP_ADMINMAIL);
  204.     else {
  205.       if (!(@ftp_chdir($conn_id$this->DESTINATION))) {
  206.         ftp_mkdir($conn_id$this->DESTINATION);
  207.         ftp_chdir($conn_id$this->DESTINATION);
  208.       }
  209.       $upload_result ftp_put($conn_id$this->FINAL_NAME$this->FILE['tmp_name']$this->FTP_MODE);
  210.       if (!$upload_result{
  211.         $result $lang['upload']['ftp_transfert_error'];
  212.       else {
  213.         $result true;
  214.       }
  215.       ftp_close($conn_id);
  216.     }
  217.     return $result;
  218.   }
  219.  
  220.   /**
  221.    * upload::UploadFile()
  222.    * upload d'un fichier
  223.    *
  224.    * @access public
  225.    * @param string $file : tableau contenant les caractéristiques du fichier à télécharger
  226.    * @param string $final_name : nom de sortie du fichier
  227.    * @param string $destination : répertoire de destination du fichier
  228.    * @return boolean : Message d'erreur ou True;
  229.    */
  230.   function UploadFile($file$final_name$destination)
  231.   {
  232.     $this->FILE = $file;
  233.     $this->FINAL_NAME = $final_name;
  234.     $this->DESTINATION = $destination;
  235.  
  236.     /**
  237.      * echo "poids maxi en ko : " . $_POST['MAX_FILE_SIZE'] . "<br>";
  238.      * echo "nom du fichier : " . $file['name'] . "<br>";
  239.      * echo "nom temp du fichier : " . $file['tmp_name'] . "<br>";
  240.      * echo "taille du fichier : " . $file['size'] . "<br>";
  241.      * echo "type du fichier : " . $file['type'] . "<br>";
  242.      * echo "ereur du fichier : " . $file['error'] . "<br>";
  243.      * echo "nom final du fichier : " . $final_name . "<br>";
  244.      * echo "destination du fichier : " . $destination . "<br>";
  245.      * echo "methode de transfert du fichier : " . $method . "<br>";
  246.      */
  247.  
  248.     switch (UPLOAD_METHOD{
  249.       case 'FTP':
  250.         $result $this->_FTPUpload();
  251.         break;
  252.       case 'HTTP':
  253.         $result $this->_HTTPUpload();
  254.         break;
  255.       default:
  256.         $result $this->_HTTPUpload();
  257.         break;
  258.     }
  259.  
  260.     return $result;
  261.   }
  262. }
  263.  
  264. ?>

Documentation generated on Sat, 08 Nov 2008 14:51:33 +0100 by phpDocumentor 1.4.1