par
tycoons » 08 déc. 2017, 13:23
Bonjour a tous,
j'ai une erreur étrange avec mon try and cache de formulaire et je ne voie pas ou sa peche:
try {
if(!isset($_FILES,$_POST["upload"]))
{
$tab = array("post "=> $_POST,"files" => $_FILES);
$de=$_POST['email_de'];
$a=$_POST['a'];
$sujet=$_POST['sujet'];
$msg=$_POST['msg'];
}
if(empty($_POST['email_de']))
{
throw new RuntimeException('votre email est obligatoire.');
}
if(empty($_POST['sujet']))
{
throw new RuntimeException('le sujet est obligatoire.');
}
if ( !isset($_FILES['file']['error']) || is_array($_FILES['file']['error']) )
{
throw new RuntimeException('parametre invalide.');
}
switch ($_FILES['file']['error'])
{
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_NO_FILE:
throw new RuntimeException('le fichier n as pas été envoyer');
break;
case UPLOAD_ERR_INI_SIZE:
break;
case UPLOAD_ERR_FORM_SIZE:
throw new RuntimeException('la taille est trop grande');
break;
default:
throw new RuntimeException('Erruer inconnue');
}
// Cheking file size.
if ($_FILES['file']['size'] > 209715200 )
{
throw new RuntimeException('La Taille du fichier est trop grosse 200MO maxi.');
}
// Check MIME Type
$finfo = new finfo(FILEINFO_MIME_TYPE);
if ( false === $ext = array_search(
$finfo->file($_FILES['file']['tmp_name']),
array(
// ms office
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'doc' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xls' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
// adobe
'pdf' => 'application/pdf',
// archives
'zip' => 'application/zip,application/x-zip,application/x-zip-compressed',
'rar' => 'application/x-rar-compressed',
),
true
))
{
throw new RuntimeException('Le format du fichier est invalide.');
}
//ici j insert dans ma base et j envoie un mail
catch (RuntimeException $e) {
echo $e->getMessage();
}
mais j ai une erreur lors de l envoi de mon fichier les zip et rar sa me dit format invalide
pourtant je me suis baser sur sa pour la versification de files:
http://php.net/manual/en/features.file-upload.php
je doit avoir une erreur de syntaxe mais je la vois pas
merci pour votre aide
Bonjour a tous,
j'ai une erreur étrange avec mon try and cache de formulaire et je ne voie pas ou sa peche:
[PHP] try {
if(!isset($_FILES,$_POST["upload"]))
{
$tab = array("post "=> $_POST,"files" => $_FILES);
$de=$_POST['email_de'];
$a=$_POST['a'];
$sujet=$_POST['sujet'];
$msg=$_POST['msg'];
}
if(empty($_POST['email_de']))
{
throw new RuntimeException('votre email est obligatoire.');
}
if(empty($_POST['sujet']))
{
throw new RuntimeException('le sujet est obligatoire.');
}
if ( !isset($_FILES['file']['error']) || is_array($_FILES['file']['error']) )
{
throw new RuntimeException('parametre invalide.');
}
switch ($_FILES['file']['error'])
{
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_NO_FILE:
throw new RuntimeException('le fichier n as pas été envoyer');
break;
case UPLOAD_ERR_INI_SIZE:
break;
case UPLOAD_ERR_FORM_SIZE:
throw new RuntimeException('la taille est trop grande');
break;
default:
throw new RuntimeException('Erruer inconnue');
}
// Cheking file size.
if ($_FILES['file']['size'] > 209715200 )
{
throw new RuntimeException('La Taille du fichier est trop grosse 200MO maxi.');
}
// Check MIME Type
$finfo = new finfo(FILEINFO_MIME_TYPE);
if ( false === $ext = array_search(
$finfo->file($_FILES['file']['tmp_name']),
array(
// ms office
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'doc' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xls' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
// adobe
'pdf' => 'application/pdf',
// archives
'zip' => 'application/zip,application/x-zip,application/x-zip-compressed',
'rar' => 'application/x-rar-compressed',
),
true
))
{
throw new RuntimeException('Le format du fichier est invalide.');
}
//ici j insert dans ma base et j envoie un mail
catch (RuntimeException $e) {
echo $e->getMessage();
}
[/PHP]
mais j ai une erreur lors de l envoi de mon fichier les zip et rar sa me dit format invalide
pourtant je me suis baser sur sa pour la versification de files: [url]http://php.net/manual/en/features.file-upload.php[/url]
je doit avoir une erreur de syntaxe mais je la vois pas
merci pour votre aide