upload.php 1.64 KB
Newer Older
Okthane's avatar
Okthane committed
1
<?php
Okthane's avatar
p  
Okthane committed
2
 //dossier temporaitre pour les images
Okthane's avatar
Okthane committed
3
define('PATH_TO_TEMP', "temp" ); 
4

5
// Vérifier si le formulaire a été soumis
Okthane's avatar
Okthane committed
6 7
if($_SERVER["REQUEST_METHOD"] == "POST")
{
Okthane's avatar
Okthane committed
8
    // Format de la réponse
MARQUE Pierre's avatar
MARQUE Pierre committed
9 10
    if(isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0)
    {
Okthane's avatar
Okthane committed
11
        $allowed = array(
Okthane's avatar
Okthane committed
12
            "jpg"  => "image/jpeg",
Okthane's avatar
Okthane committed
13
            "jpeg" => "image/jpeg",
Okthane's avatar
Okthane committed
14 15 16
            "png"  => "image/png",
            "PNG"  => "image/PNG",
            "JPG"  => "image/JPG"
Okthane's avatar
Okthane committed
17
        );
Okthane's avatar
Okthane committed
18
        $filename    = htmlspecialchars(trim($_FILES["photo"]["name"]));// évite les noms de fichiers trop exotiques 
Okthane's avatar
Okthane committed
19
        $newfilename = $filename;
Okthane's avatar
Okthane committed
20 21 22 23 24 25 26
        $filetype    = $_FILES["photo"]["type"];
        $filesize    = $_FILES["photo"]["size"];
        $message     = "";

        $error      = true; 
        $errorSize  = true;
        $errorMIME  = true;
27 28 29

        // Vérifie l'extension du fichier
        $ext = pathinfo($filename, PATHINFO_EXTENSION);
30
        if(array_key_exists($ext, $allowed))//die("Erreur : Veuillez sélectionner un format de fichier valide.");
MARQUE Pierre's avatar
MARQUE Pierre committed
31
        {
Okthane's avatar
Okthane committed
32 33
            // Vérifie le type MIME du fichier ATTENTION - VERIFIE SEULEMENT L'EXTENSION
            if(in_array($filetype, $allowed))
MARQUE Pierre's avatar
MARQUE Pierre committed
34
            {
Okthane's avatar
Okthane committed
35
                $errorMIME = false;
36 37
            }
        }
Okthane's avatar
Okthane committed
38
        $maxsize = 1 * 1024 * 1024;
Okthane's avatar
Okthane committed
39
        if(!($filesize > $maxsize))
Okthane's avatar
Okthane committed
40 41
        {
            $errorSize = false;
42 43
        }
    }
Okthane's avatar
Okthane committed
44
    $error = $errorMIME || $errorSize;
Okthane's avatar
Okthane committed
45
    $data  = array(
Okthane's avatar
Okthane committed
46 47 48
        
        "errorMIME" => $errorMIME,
        "errorSize" => $errorSize,
Okthane's avatar
Okthane committed
49
        "error"     => $error,//<----- Prend la valeur true (erreur!) ou false (ouf!)
Okthane's avatar
Okthane committed
50

Okthane's avatar
Okthane committed
51 52
    );
    echo json_encode($data);
53
}
Okthane's avatar
Okthane committed
54
?>
Okthane's avatar
Okthane committed
55