93 $this->max_image_width = $width;
94 $this->max_image_height = $height;
106 for ($i = 0; $i < 4; $i++) {
107 $file_var =
'$' .
$filename . (($index[$i] !=
"file") ?
"_" . $index[$i] :
"");
108 eval(
'global ' . $file_var .
';');
109 eval(
'$this->file[$index[$i]]=' . $file_var .
';');
112 if ($this->file[
"file"] && $this->file[
"file"] !=
"none") {
115 $this->errors[] =
"Taille maximale dépassée:. Le fichier ne doit pas excéder " . $this->
max_filesize / 1000 .
"KB.";
118 if (preg_match(
"/image/", $this->file[
"type"])) {
120 $image = getimagesize($this->file[
"file"]);
121 $this->file[
"width"] = $image[0];
122 $this->file[
"height"] = $image[1];
124 if (($this->max_image_width || $this->max_image_height) && (($this->file[
"width"] > $this->max_image_width) || ($this->file[
"height"] > $this->max_image_height))) {
125 $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";
130 $this->file[
"extension"] =
".gif";
134 $this->file[
"extension"] =
".jpg";
138 $this->file[
"extension"] =
".png";
142 $this->file[
"extension"] = $extension;
145 }
else if (!preg_match(
"/(\.)([a-z0-9]{3,5})$/", $this->file[
"name"]) && !$extension) {
147 switch ($this->file[
"type"]) {
149 $this->file[
"extension"] =
".txt";
156 $this->file[
"extension"] = $extension;
160 $pattern = preg_quote($accept_type);
161 if (preg_match(
"/$pattern/", $this->file[
"type"])) {
162 $this->accepted = True;
164 $this->errors[] =
"Seuls les fichiers de type " . preg_replace(
"/\|/",
" or ", $accept_type) .
" sont acceptés";
167 $this->accepted = True;
170 $this->errors[] =
"Fichier introuvable...";
179 if ($this->accepted) {
180 if (!file_exists(
$path)) {
185 $new_name = preg_replace(
"/[^a-z0-9._]/",
"", preg_replace(
"/ /",
"_", preg_replace(
"/%20/",
"_", strtolower($this->file[
"name"]))));
187 if (preg_match(
"/(\.)([a-z0-9]{3,5})$/", $new_name)) {
188 $pos = strrpos($new_name,
".");
189 if (!isset($this->file[
"extension"])) {
190 $this->file[
"extension"] = substr($new_name, $pos, strlen($new_name));
192 $new_name = substr($new_name, 0, $pos);
194 $new_name = uniqid(
"") .
"_" . $new_name;
195 if (!isset($this->file[
"extension"])) $this->file[
"extension"] =
"";
196 $this->new_file =
$path . $new_name . $this->file[
"extension"];
197 $NEW_NAME = $new_name . $this->file[
"extension"];
201 $aok = copy($this->file[
"file"], $this->new_file);
205 while (file_exists(
$path . $new_name . $copy . $this->file[
"extension"])) {
206 $copy =
"_copy" . $n;
209 $this->new_file =
$path . $new_name . $copy . $this->file[
"extension"];
210 $aok = copy($this->file[
"file"], $this->new_file);
214 if (file_exists($this->new_file)) {
215 $this->errors[] =
"Le fichier "" . $this->new_file .
"" existe déjà";
217 $aok = rename($this->file[
"file"], $this->new_file);
225 unset($this->new_file);