1
I’m trying to save an image I get through form.
I’m using move_uploaded_file()
for that reason.
At the moment, my code is this way:
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 I receive form data:
$image = $_FILE['image'];
$saveImage = new Image();
$destinationImg = $saveImage->save($image);
But when I check the directory, the image is not there.
And the $resultImg
always returns to me false
.
Within the class try to call it that,
$image['nome_input_html']['tmp_name']
, in doubtprint_r($image)
– rray
@Rray Continued the same way...
– Naldson
Ahhh is
$_FILES
ta missing as
there in the code.– rray
That’s right, rray! True. But still returns me false. :(
– Naldson
And print_r() returned q?
– rray
I gave a print_r on the variable $image, and it returned me the following:
[type] => image/jpeg [tmp_name] => /tmp/phpnjYqd1 [error]
– Naldson
It may be an error of permission or that the folder does not exist etc. It does so p catch the error,
if(!move_upload(......parametros.....){ print_r(error_get_last());}
– rray
Wouldn’t it be move_uploaded_files()? When I use
move_upload
he returns me call to Undefined Function– Naldson
That’s right, haha typed wrong xD
– rray
Let’s go continue this discussion in chat.
– Naldson
I was able to fix it... it was just a mistake on the var
$destination
class. It turns out that she was in a subfolder and had to be in fact../public/img/
.– Naldson