-1
You guys, good morning, I’m having a little problem, simple but boring, I have a form that sends some information and images, and this form is editable, the information is changed perfectly, I’m having trouble with the image, so it seems to be changing, But only in the bank, the directory folder is empty, you have to display the image without the directory? because when the form is sent for the first time it is all right the image is displayed without errors, however when I change it does not go to the directory. If anyone can help, I’d appreciate it
salva_ed.php
<?php
//inicia conexão com o banco
include ("conexao.php");
$new_name = "";
// recebe o codigo do registro
$iden = isset($_POST['iden'])?$_POST['iden']:"";
$iden = $_POST ['codigo'];
$arquivo = isset($_FILES['arquivo'])?$_FILES['arquivo']:"";
$arquivo = $_FILES ['arquivo'];
// aqui seria onde ele veifica se existe algo no campo arquivo e o substitui por um valor em branco
if($arquivo == ""){
$query =("update eqp set arquivo = '' WHERE codigo='$iden'");
}else{
// aqui seria onde fazia o update da imagem, dando um novo nome e movendo para a pasta de upload
if(isset($_FILES['imagem']))
{
$sql = mysqli_query("SELECT * FROM eqp WHERE codigo = '$iden' ");
$escrever=mysql_fetch_array($sql);
date_default_timezone_set("Brazil/East"); //Definindo timezone padrão
$ext = strtolower(substr($_FILES['imagem']['name'],-4)); //Pegando extensão do arquivo
$new_name = $resultado['foto']; //Definindo um novo nome para o arquivo
$dir ='uploads/'; //Diretório para uploads
move_uploaded_file($_FILES['imagem']['tmp_name'], $dir.$new_name); //Fazer upload do arquivo
}
$new_name = $_FILES['arquivo']["name"];
$imagem = $new_name;
var_dump($imagem);
echo '<pre>';
print_r($imagem);
echo '</pre>';
$query=("UPDATE eqp SET arquivo= '$imagem' WHERE codigo='$iden'");
$result = mysqli_query($conexao,$query);
// Verifica se o comando foi executado com sucesso
if(!$result)
echo "Registro NÃO alterado.";
else
echo "Registro Alterado com sucesso.";
}
?>
final message
string(12) "IMG_6175.JPG"
IMG_6175.JPG
Registro Alterado com sucesso.
Do you know if the folder has the permissions set the right way? Sometimes the file is not written because the system is not letting the code access the folder.
– adrianosmateus
hello @adrianosmateus thanks for the attention, man, I suspected this too and took a look, is this with the permission right, because as said, when and sent without being changed the image will right to the directory and is displayed normally.
– noobphp
You can post the HTML code of the data submission form?
– adrianosmateus
so this is how the html code @adrianosmateus <form method="post" action="parses 1.php" enctype="Multipart/form-data"><form> <div class="form-group"> <input type="Submit" class="bnt save" value="Send"> label<for="inputEmail3" class="col-Sm-2 control-label">Image:</label> <div class="col-Sm-10"> <H5>Attached file: <font color="#00BFFF">*</font></H5> </input type="file" class= "attachment"name"> </div> </div> </form</form>
– noobphp
I saw that there is another <form> tag after the <form method="post" action="parse.php" enctype="Multipart/form-data">. Take that tag off and try again.
– adrianosmateus
face, that and my home page, that form that is responsible for editing and is like this : <form method='post' enctype='Multipart/form-data' action='salva_ed.php''> <td>Code:</td><td> <input type='text' name='code' value='" . $code . " '> </td> <td>Attached file: <input type='file' class= 'attachment' name='file'> </td> <br><<br> </tr> <br> <input type='Submit' class='bnt save' value='Save'>
– noobphp