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
| <?php
// Testons si le fichier a bien été envoyé et s'il n'y a pas d'erreur
if (isset($_FILES['monfichier']) AND $_FILES['monfichier']['error'] == 0)
{
// Testons si le fichier n'est pas trop gros
if ($_FILES['monfichier']['size'] <= 5048576)
{
// Testons si l'extension est autorisée
$infosfichier = pathinfo($_FILES['monfichier']['name']);
$extension_upload = $infosfichier['extension'];
$extensions_autorisees = array(
'application/txt' => 'txt',
'application/docx' => 'docx',
'image/gif' =>'gif',
'image/jpeg' => 'jpeg',
'image/png' =>'png',
'image/tiff' => 'tiff',
'image/jpg' => 'jpg'
);
if (in_array($extension_upload, $extensions_autorisees))
{
// On peut valider le fichier et le stocker définitivement
$destination_fichier = 'uploads/' . time() . '.' .$extension_upload;
move_uploaded_file($_FILES['monfichier']['tmp_name'], $destination_fichier);
echo "L'envoi a bien été effectué !";
}
elseif ($extension_upload != $extensions_autorisees)
{
echo "Vous devez uploader un fichier de type png, gif, jpg, jpeg, txt ou doc...";
}
}
elseif ($_FILES['monfichier']['size'] > 5048576)
{
echo 'Le fichier semble trop gros';
}
}
else
{
echo 'Erreur lors du traitement. Vous n\'avez spécifié aucun fichier.';
}
?> |