Пример #1
0
/** afficher_image_attach() - genere une image en cache (gestion taille et vignettes) et l'affiche comme il faut
 *
 * @param   string	nom du fichier image
 * @param   string	label pour l'image
 * @param   string	classes html supplementaires
 * @param   int		largeur en pixel de la vignette
 * @param   int		hauteur en pixel de la vignette
 * @param   int		largeur en pixel de l'image redimensionnee
 * @param   int		hauteur en pixel de l'image redimensionnee
 * @return  html    affichage a l'ecran
 */
function afficher_image_attach($idfiche, $nom_image, $label, $class, $largeur_vignette, $hauteur_vignette)
{
    $oldpage = $GLOBALS['wiki']->GetPageTag();
    $GLOBALS['wiki']->tag = $idfiche;
    $GLOBALS['wiki']->page['time'] = date('YmdHis');
    $GLOBALS['wiki']->setParameter("desc", $label);
    $GLOBALS['wiki']->setParameter("file", $nom_image);
    $GLOBALS['wiki']->setParameter("class", $class);
    $GLOBALS['wiki']->setParameter("width", $largeur_vignette);
    $GLOBALS['wiki']->setParameter("height", $hauteur_vignette);
    if (!class_exists('attach')) {
        include 'tools/attach/actions/attach.class.php';
    }
    $attach = new Attach($GLOBALS['wiki']);
    ob_start();
    $attach->doAttach();
    $output = ob_get_contents();
    ob_end_clean();
    $GLOBALS['wiki']->tag = $oldpage;
    $output = preg_replace('/width=\\".*\\".*height=\\".*\\"/U', '', $output);
    preg_match_all('/(\\<img.*\\/\\>)/U', $output, $matches);
    return $matches[0][0];
}
Пример #2
0
 /**
  * Returns array('success'=>true) or array('error'=>'error message')
  */
 function handleUpload($uploadDirectory, $replaceOldFile = FALSE)
 {
     if (!is_writable($uploadDirectory)) {
         return array('error' => "Le dossier de t&eacute;l&eacute;chargement n'est pas accessible en &eacute;criture.");
     }
     if (!$this->file) {
         return array('error' => 'Pas de fichiers envoy&eacute;s.');
     }
     $size = $this->file->getSize();
     if ($size == 0) {
         return array('error' => 'Le fichier est vide.');
     }
     if ($size > $this->sizeLimit) {
         return array('error' => 'Le fichier est trop large.');
     }
     $pathinfo = pathinfo($this->file->getName());
     $filename = $pathinfo['filename'];
     //$filename = md5(uniqid());
     $ext = strtolower($pathinfo['extension']);
     if ($this->allowedExtensions && !in_array($ext, $this->allowedExtensions)) {
         $these = implode(', ', $this->allowedExtensions);
         return array('error' => "Le fichier n'a pas une extension autoris&eacute;e, voici les autoris&eacute;es : " . $these . '.');
     }
     /*if(!$replaceOldFile){
           /// don't overwrite previous files that were uploaded
           while (file_exists($uploadDirectory . $filename . '.' . $ext)) {
               $filename .= rand(10, 99);
           }
       }*/
     // on enleve les espaces et les accents pour le nom de fichier
     $search = array('@[éèêëÊË]@i', '@[àâäÂÄ]@i', '@[îïÎÏ]@i', '@[ûùüÛÜ]@i', '@[ôöÔÖ]@i', '@[ç]@i', '@[ ]@i', '@[^a-zA-Z0-9_]@');
     $replace = array('e', 'a', 'i', 'u', 'o', 'c', '_', '');
     $filename = preg_replace($search, $replace, utf8_decode($filename));
     $attach = new Attach($GLOBALS['wiki']);
     $GLOBALS['wiki']->setParameter("desc", $filename);
     $GLOBALS['wiki']->setParameter("file", $filename . '.' . $ext);
     // dans le cas d'une nouvelle page, on donne une valeur a la date de création
     if ($GLOBALS['wiki']->page['time'] == '') {
         $GLOBALS['wiki']->page['time'] = date('YmdHis');
     }
     // on envoi l'attachement en retenant l'affichage du résultat dans un buffer
     ob_start();
     $attach->doAttach();
     $fullfilename = $attach->GetFullFilename(true);
     ob_end_clean();
     if ($this->file->save($fullfilename)) {
         return array_map('utf8_encode', array('success' => true, 'filename' => $fullfilename, 'simplefilename' => $filename . '.' . $ext, 'extension' => $ext));
     } else {
         return array_map('utf8_encode', array('error' => 'Impossible de sauver le fichier.' . "L'upload a &eacute;t&eacute; annul&eacute; ou le serveur a plant&eacute;."));
     }
 }