- if (isset($_FILES['newpj'])) {
- $this->custom = $this->custom_mp;
- $body = "\n--".$this->boundary."\n".$this->custom_bd."\n\n".$body."\n--".$this->boundary."\n";
- $tmpname = $_FILES['newpj']['tmp_name'];
- $file = basename($_FILES['newpj']['name']);
- $mime = shell_exec("file -bi $tmpname"); //Because mime_content_type don't work :(
- if (preg_match("@([^ ]+/[^ ]+); (.*)@", $mime, $format)) {
- $mime = $format[1];
- $encod = $format[2];
- } else {
- preg_match("@([^ ]+/[^ ]+)\r?\n@", $mime, $format);
- $mime = $format[1];
- $encod = 'base64';
- }
-
- $body .= 'Content-Type: '.$mime.'; name="'.$file."\"\n";
- $body .= 'Content-Disposition: attachment; filename="'.$file."\"\n";
- $body .= 'Content-Transfer-Encoding: '.$encod."\n\n";
- if ($encod == 'base64') {
- $body .= chunk_split(base64_encode(fread(fopen($tmpname, 'r'), filesize($tmpname))));
- } else {
- $body .= fread(fopen($tmpname, 'r'), filesize($tmpname));
- }
- $body .= '--'.$this->boundary.'--';
- }
+ $uploaded = $this->_upload('newpj');
+ switch ($uploaded['error']) {
+ case UPLOAD_ERR_OK:
+ $this->custom = $this->custom_mp.$this->custom;
+ $body = $this->_make_part($body_headers, $body);
+ $file_head = 'Content-Type: '.$uploaded['type'].'; name="'.$uploaded['name']."\"\n"
+ . 'Content-Transfer-Encoding: '.$uploaded['encoding']."\n"
+ . 'Content-Disposition: attachment; filename="'.$uploaded['name']."\"\n";
+ $body .= $this->_make_part($file_head, $uploaded['data']);
+ $body .= "\n--".$this->boundary.'--';
+ break;
+
+ case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE:
+ return '<p class="error">'._b_('Fichier trop gros pour être envoyé : ')
+ .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
+
+ case UPLOAD_ERR_PARTIAL:
+ return '<p class="error">'._b_('Erreur lors de l\'upload de ')
+ .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
+
+ case UPLOAD_ERR_NO_FILE:
+ return '<p class="error">'._b_('Le fichier spécifié n\'existe pas : ')
+ .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
+
+ case UPLOAD_ERR_NO_TMP_DIR:
+ return '<p class="error">'._b_('Une erreur est survenue sur le serveur lors de l\'upload de ')
+ .$uploaded['name'].'</p>'.$this->action_showThread($group, $artid);
+
+ default:
+ $this->custom = $body_headers.$this->custom;
+ }