2
I have a form (in php, I wanted to ask if it works without problem? ) to insert images (the path of them) and when I enter the notification appears that were inserted in the database but the image does not move to the folder I ask for.
This is the code I made to transfer:
<?php
include '../conn.php';
mysqli_set_charset($con,"utf8");
$id = $_GET['id'];
$imagem = $_FILES['imagem']['tmp_name'];
$img_name = $_FILES['imagem']['name'];
$dir = "../imagens/viaturas/";
$path = $dir.$img_name;
move_uploaded_file( $imagem, $path );
$sql = "INSERT INTO carros_img(id_fk, img) VALUES ($id, '$img_name')";
if(mysqli_query($con, $sql)){
echo "<script>
document.location.href = '../admin/carros.php?id=$id';
</script>";
}
else{
echo "<script>
alert('Imagem não enviada');
document.location.href = '../admin/quem.php?id=$id';
</script>";
}
?>
The path image appears in the comic but the image does not move from folder. Some problem with the code?
Is there a mistake? Maybe it has to do with permissions
– Miguel
No, there is no error just don’t move the image.
– Bruno Gibellino
You have permissions to write to the folder you refer to?
– Luís Almeida
The folder path is correct ?
– Luís Almeida
The way is right but permission do not know. How to make permission ?
– Bruno Gibellino
Just look at the properties of the folder.. but eventually that won’t be the problem. add this, to your code and see if there are any errors: error_reporting(E_ALL);
– Luís Almeida
Place at the beginning of this code these three lines:
ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);
execute the code if it is not it shows you the error.– novic
Bruno, post in the question the tree of your project, including the folder where you are running this script and the folder where you want to save please!
– Kenny Rafael
Permission 755 in the folder where the files will be moved. If no error is shown the paths seem to be correct.
– Matheus Zenker