1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
<?php
require_once("gallery_config.php");
require_once("gallery_utils.php");
/*
* Code pour envoyer une image
*
// Ecouteur permettant d'envoyer une image
if (isset($_POST['upload']) && isset($_POST['gallery_path']) && isset($_FILES['fichier']))
{
// Envoyer l'image
echo gallery_upload_image($_FILES['fichier'], $_POST['gallery_path']);
}
*
*/
// ------------------------------------------------------------------------------------------------------------------------------------------------------ //
// - Fonction Upload Image //
// ------------------------------------------------------------------------------------------------------------------------------------------------------ //
function gallery_upload_image($file, $path)
{
global $largeThumbSize, $smallThumbSize;
$ret = "";
/*
* Fonction d'upload
*
*/
$ret .= "<div class=\"content\">\n";
// Contrôler les erreurs sur fichier
if ($file['error'])
return $ret .= "\t- Erreur : " . $file['error'] . " -\n</div>\n";
// Si la gallerie de destination existe
if (!file_exists($path))
return $ret .= "\t- Dossier de destination invalide -\n</div>\n";
$tmp_file = $file['tmp_name'];
// Vérifier que le fichier à été correctement uploadé
if (!is_uploaded_file($tmp_file))
return $ret .= "\t- Fichier introuvable -\n</div>\n";
// Vérifier que le fichier n'est pas déja présent
if (file_exists($path . $file['name']))
return $ret .= "\t- Le fichier " . $file['name'] . " existe déja -\n</div>\n";
// Contrôler le nom du fichier
if (preg_match('#[\x00-\x1F\x7F-\x9F/\\\\]#', $file['name']) || (substr_count($file['name'],'.') > 1))
return $ret .= "\t- Ce nom de fichier est interdit pour des raisons de sécurité -\n</div>\n";
// Contrôler l'extention du fichier
$mimes = array("image/jpeg","image/gif","image/png");
$type = mime_type_file (strtolower($file['name']));
if (!in_array($type,$mimes))
return $ret .= "\t- Les fichiers " . $file['type'] . " ne sont pas supportés -\n</div>\n";
// Déplacer le fichier
if (!move_uploaded_file($tmp_file, $path . $file['name']))
return $ret .= "- Impossible de déplacer le fichier vers le répertoire de destination -\n</div>\n";
$ret .= "Le fichier " . $file['name'] . " a bien été uploadé<br />\n";
// Si les dossiers pour les thumbnails n'existent pas, ils sont crées
if (!file_exists($path . "thumbSmall/"))
{
if (!mkdir($path."thumbSmall", 0755))
return $ret .= "\t- Impossible de créer le répertoire " . $path . "thumbSmall -\n</div>\n";
}
if (!file_exists($path . "thumbLarge/"))
{
if (!mkdir($path."thumbLarge", 0755))
return $ret .= "\t- Impossible de créer le répertoire " . $path . "thumbLarge -\n</div>\n";
}
// Créer les thumbnails
$ret .= "Création de vignette " . $smallThumbSize . "x" . $smallThumbSize . " : " . create_thumb($path . $file['name'], $path."thumbSmall/".$file['name'], $type, $smallThumbSize, $smallThumbSize) . "<br />\n";
$ret .= "Création de vignette " . $largeThumbSize . "x" . $largeThumbSize . " : " . create_thumb($path . $file['name'], $path."thumbLarge/".$file['name'], $type, $largeThumbSize, $largeThumbSize) . "<br />\n";
$ret .= "</div>\n";
return $ret;
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------ //
// - Fonction Upload Image form //
// ------------------------------------------------------------------------------------------------------------------------------------------------------ //
function gallery_upload_image_form($option, $dest)
{
global $galleryPath;
$ret = "";
/*
* Affiche et formatte un formulaire
* destiné à envoyer des
* fichiers image sur le serveur
*
*/
$ret .= "<div class=\"content\">\n";
$ret .= "\t<form method=\"post\" enctype=\"multipart/form-data\" action=\"". $dest ."\">\n";
$ret .= "\t\t<select name=\"gallery_path\">\n";
$ret .= "\t\t\t<option value=\"\">Choisir une gallerie</option>\n";
$ret .= "\t\t\t<option value=\"\">--</option>\n";
// Pour chaque option
foreach ($option as $op)
$ret .= "\t\t\t<option value=\"" . $galleryPath .$op . "/\">" . $op . "</option>\n";
$ret .= "\t\t</select>\n";
$ret .= "\t\t<input type=\"file\" name=\"fichier\" size=\"30\"><input type=\"submit\" name=\"upload\" value=\"Envoyer\">\n";
$ret .= "\t</form>\n";
$ret .= "</div>\n";
return $ret;
}
?> |
Partager