92 $this->max_image_width = $width;
93 $this->max_image_height = $height;
105 for ($i = 0; $i < 4; $i++) {
106 $file_var =
'$' .
$filename . (($index[$i] !=
"file") ?
"_" . $index[$i] :
"");
107 eval(
'global ' . $file_var .
';');
108 eval(
'$this->file[$index[$i]]=' . $file_var .
';');
111 if ($this->file[
"file"] && $this->file[
"file"] !=
"none") {
114 $this->errors[] =
"Taille maximale dépassée:. Le fichier ne doit pas excéder " . $this->
max_filesize / 1000 .
"KB.";
117 if (preg_match(
"/image/", $this->file[
"type"])) {
119 $image = getimagesize($this->file[
"file"]);
120 $this->file[
"width"] = $image[0];
121 $this->file[
"height"] = $image[1];
123 if (($this->max_image_width || $this->max_image_height) && (($this->file[
"width"] > $this->max_image_width) || ($this->file[
"height"] > $this->max_image_height))) {
124 $this->errors[] =
"Les dimensions de l'image sont trop importantes. " .
"L'image ne doit pas faire plus de : " . $this->max_image_width .
" x " . $this->max_image_height .
" pixels";
129 $this->file[
"extension"] =
".gif";
133 $this->file[
"extension"] =
".jpg";
137 $this->file[
"extension"] =
".png";
141 $this->file[
"extension"] = $extension;
144 }
else if (!preg_match(
"/(\.)([a-z0-9]{3,5})$/", $this->file[
"name"]) && !$extension) {
146 switch ($this->file[
"type"]) {
148 $this->file[
"extension"] =
".txt";
155 $this->file[
"extension"] = $extension;
159 $pattern = preg_quote($accept_type,
"/");
160 if (preg_match(
"/$pattern/", $this->file[
"type"])) {
161 $this->accepted = True;
163 $this->errors[] =
"Seuls les fichiers de type " . preg_replace(
"/\|/",
" or ", $accept_type) .
" sont acceptés";
166 $this->accepted = True;
169 $this->errors[] =
"Fichier introuvable...";
178 if ($this->accepted) {
179 if (!file_exists(
$path)) {
184 $new_name = preg_replace(
"/[^a-z0-9._]/",
"", preg_replace(
"/ /",
"_", preg_replace(
"/%20/",
"_", strtolower($this->file[
"name"]))));
186 if (preg_match(
"/(\.)([a-z0-9]{3,5})$/", $new_name)) {
187 $pos = strrpos($new_name,
".");
188 if (!isset($this->file[
"extension"])) {
189 $this->file[
"extension"] = substr($new_name, $pos, strlen($new_name));
191 $new_name = substr($new_name, 0, $pos);
193 $new_name = uniqid(
"") .
"_" . $new_name;
194 if (!isset($this->file[
"extension"])) $this->file[
"extension"] =
"";
195 $this->new_file =
$path . $new_name . $this->file[
"extension"];
196 $NEW_NAME = $new_name . $this->file[
"extension"];
200 $aok = copy($this->file[
"file"], $this->new_file);
204 while (file_exists(
$path . $new_name . $copy . $this->file[
"extension"])) {
205 $copy =
"_copy" . $n;
208 $this->new_file =
$path . $new_name . $copy . $this->file[
"extension"];
209 $aok = copy($this->file[
"file"], $this->new_file);
213 if (file_exists($this->new_file)) {
214 $this->errors[] =
"Le fichier "" . $this->new_file .
"" existe déjà";
216 $aok = rename($this->file[
"file"], $this->new_file);
224 unset($this->new_file);
upload($filename, $accept_type, $extension)
max_image_size($width, $height)