move_uploaded_file saved in database, but not saved image in folder! Help

Asked

Viewed 68 times

3

<h1>Upload de Arquivos</h1>

<form name="enviarImagem" action="enviar.php" method="POST" enctype="multipart/form-data">
Arquivo<br> <input type="file" name="img" value=""><br><br>
<input type="submit" value="Enviar" name ="enviar">





<?php



$name = $_FILES["img"]["name"];
$temp = $FILES["img"]["tmp_name"];

/*var_dump($name);
var_dump($temp);*/

$banco = new mysqli("localhost", "root", "", "projeto");

$sql = "INSERT INTO imagem (nome) VALUES ('{$name}')";

$banco->query($sql);
$banco->close();


move_uploaded_file($temp, "./imagens/".$name);

header("Location: upload.php");

?>
  • 1

    Check that the folder is allowed. Also check that the path is correct by giving the realpath("./images/".$name) command; and see if it is correct.

  • 1

    in one of the $_FILES missing a _

2 answers

0

Good afternoon,

Try the following code:

$link = "nomepasta/".$_FILES["img"]["name"];

move_uploaded_file($_FILES['img']['tmp_name'], $link);

0

Hello, try it like this:

File Upload

Filing cabinet


<?php

$name = $_FILES["img"]["name"];
$temp = $_FILES["img"]["tmp_name"];

/*var_dump($name);
var_dump($temp);*/

$banco = new mysqli("localhost", "root", "", "projeto");

$sql = "INSERT INTO imagem (nome) VALUES ('{$name}')";

$banco->query($sql);
$banco->close();

$dir = "./imagens";

@mkdir($dir);


move_uploaded_file($temp, ".$dir."/".$name);

header("Location: upload.php");

?>

Your mistake must be because you are not giving the correct path to the image... Try putting @mkdir to create the folder and see where it was created... so you can adjust until you create the folder in the right place!

Browser other questions tagged

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