Problems saving image

1

I'm trying to save an image I get via form.

I'm using move_uploaded_file() for this.

Currently, my code looks like this:

class Image
{
    public function save($image)
    {
        $name = time();
        $destination = "public/img/vehicles/" . $name . ".jpg";
        $result = move_uploaded_file($image['tmp_name'], $destination);
        return $result;
    }
}

File that I get form data:

$image = $_FILE['image'];

$saveImage = new Image();
$destinationImg = $saveImage->save($image);

But when I check the directory, the image is not there. And $resultImg always returns false .

    
asked by anonymous 19.05.2016 / 20:06

1 answer

1

First see if the $imagem variable has a valid upload file, using the is_uploaded_file ( string $filename ) function.

class Image
{
    public function save($image)
    {
        var_dump(is_uploaded_file ($image['tmp_name']));

        $name = time();
        $destination = "public/img/vehicles/" . $name . ".jpg";
        $result = move_uploaded_file($image['tmp_name'], $destination);
        var_dump($image['error']);
        return $result;
    }
}

If the above function returns false (there is a problem with the upload file), see the apache logs (if you use apache as the server) or use the error_get_last() function.

    
20.05.2016 / 02:10