PHP - upload an image

0

Ihavethefollowingcodetouploadanimage:

var_dump($_FILES);$target_dir="uploads/";
$target_file = $target_dir . basename ( $_FILES ["fileToUpload"] ["name"] );
$uploadOk = 1;
$imageFileType = pathinfo ( $target_file, PATHINFO_EXTENSION );

if (isset ( $_POST ["submit"] )) {
    $check = getimagesize ( $_FILES ["fileToUpload"] ["tmp_name"] );
    if ($check !== false) {
        echo "File is an image - " . $check ["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}

but the following error appears when loading the image: array (1) {["fileToUpload"] = > array (5) {["name"] = > string (8) "css3.jpg" ["type"] = > string (10) "image / jpeg" ["tmp_name"] = > string (14) "/ tmp / php8UjGak" ["error"] = > int (0) ["size"] = > int (21455)}} File is an image - image / jpeg.

    
asked by anonymous 25.05.2017 / 21:37

1 answer

0

From what looks like his code worked, he checked it's an image. What appeared to you was the output of var_dump ($ _FILES);

Instead of echo: "File is an image -". $ check ["mime"]. "."; You should write your code that defines what will do with this image (usually move to a permanent directory).

    
25.05.2017 / 21:41