0
I’m trying to update an image with HTML, Ajax and PHP.
HTML and Ajax are configured correctly, as far as I know. But I think the problem is in php. because it works but returns me error. my php.
<?php
require_once('conexao.php');
if($_SERVER["REQUEST_METHOD"] == "POST"){
$Trocar_foto_perfil = $_FILES['Trocar_img_perfil']['name'];
echo 'Esse é o nome da minha imagem : '.$Trocar_foto_perfil;
session_start();
$On_muda_foto = $_SESSION['Foto_s'];
echo 'Esse é o ID : '.$On_muda_foto;
$_UP['pasta'] = 'images-profile/';
$_UP['tamanho'] = 1024*1024*100;
$_UP['extensoes'] = array('png','jpg','jpeg');
$_UP['renomear'] = false;
if($Trocar_foto_perfil == ""){
echo "Cororreu algum erro com a imagem!";
}
if(array_search($extensao, $_UP['extensao']) === false){
echo "Rapaz, não adianta tapear não. A img tem a extensão errada!";
}
if($_UP['tamanho'] < $_FILES['Trocar_img_perfil']['size']){
echo "kkkkjj ae tiw a img é muito grande nois num tem host caro n poh!";
}
else{
$Nome_img_perfil = $_FILES['Trocar_img_perfil']['name'];
$Nome_img_perfil_final = strtolower(preg_replace("[^a-zA-Z0-9-]", "-",strtr(utf8_decode(trim($Nome_img_perfil)),utf8_decode(" "),"-")));
if(move_uploaded_file($_FILES['Trocar_img_perfil']['tmp_name'], $_UP['pasta']. $Nome_img_perfil_final)){
$SQL = mysqli_query($conex," UPDATE User_log SET Foto='$Nome_img_perfil_final' WHERE ID=$On_muda_foto");
echo '<script>history.go(0);</script>';
}
else{
echo "Ocorreu um erro!";
}
}
}
else{
};
?>
Meu Ajax
<script>
$(function(){
$(".form6").submit(function(event){
event.preventDefault();
var formDados = $(".form6").serialize();
$.ajax({
url:"/Arquivo/trocar_img.php",
type:"POST",
data:formDados,
cache:false,
processData:false,
success:function(data){
$("#ressult_log_succes_img_plus").html(data);
},
error:function(data){
$("#ressult_log_error_img_plus").html(data);
},
dataType:"html"
});
return false;
});
});
</script>
The error that returns to me are these.
Keeps making the same mistake.
– EDGNoizy
@Edgnoizy if possible post your updated code on Pastebin.com and post the link here
– Valdeir Psr
https://pastebin.com/dZAguZMq
– EDGNoizy
@Edgnoizy appears some error? I tested it here and it’s OK.
– Valdeir Psr
It says that the image does not exist, I tried to print the name of the variable that the img is and does not return me anything
– EDGNoizy
@Edgnoizy I edited my answer.
– Valdeir Psr
I got what I was trying to do, but another little problem came up. I’m setting a folder for the image to go to it but the image is not going and when it will not appear the name of the image in the bank.
– EDGNoizy