PHP - upload an image

Asked

Viewed 73 times

0

inserir a descrição da imagem aquiI have the following code to upload an image:

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 nevertheless the following error appears when I upload 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.

  • That’s not a mistake, it’s a way out var_dump()

  • rray what should I do then?

  • Just remove the var_dump()

  • rray removed and it worked, but I click "choose file" I choose the photo and then click upload, so I just want the file to appear as having been uploaded, however it does not happen to appear a blank page with the echo information. have as Voce help me pf? thanks, pf see the image, I just added

  • When writing the message send the formatted html, then you play the message inside a div with the formatting classes.

1 answer

0

It seems your code worked, he checked that it is an image. What appeared to you was the exit of var_dump ( $_FILES );

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

  • Marlon, this I have already done: $Image = $Conn->real_escape_string ( file_get_contents ( $_FILES ["fileToUpload"] ["tmp_name"]));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.