-1
HTML
<form id="formImage" enctype="multipart/form-data">
<div class="corpo">
<div class="foto">
<h5 class="white-text title">Escolha sua foto de perfil</h5>
<br>
<div class="imagem">
<label for="inputImagem"><img
src="https://cdt.org/files/2015/10/2015-10-06-FB-person.png" alt id="img_perf"
class="circle z-depth-2"></label>
<input type="file" id="inputImagem" name="foto">
</div>
<br>
</form>
<br>
<a class="btn cor_tema btn_proximo" id="prox1"><i class="material-icons">arrow_forward</i></a>
</div>
JS
$("#prox1").click(function(){
var fd = new FormData();
var files = $('#inputImagem')[0].files [0];
fd.append ('foto', files);
$.ajax({
url:"http://localhost/servidor/insereImg.php",
dataType:'json',
type:'POST',
data:fd,
contentType: false,
processData: false,
success:function(r){
if(r.Resp==1){
localStorage.setItem("Foto","http://localhost/servidor/img/" + r.Foto);
}
},
error:function(e){
console.log(e);
}
})
});
PHP
<?php
header('Content-type: application/json');
header('Access-Control-Allow-Origin:*');
if ($_FILES['foto']) {
date_default_timezone_set('America/Sao_Paulo');
$data = date('Y-m-d H:i:s');
$extensao = substr($_FILES['foto']['name'],-4);
$novoNome = md5($data).$extensao;
$diretorio = '/http://localhost/servidor/img/';
move_uploaded_file($_FILES['foto']['tmp_name'], $diretorio.$novoNome);
$img = $novoNome;
}
$resposta = array('Resp' => '1',
'Foto' => $img
);
ob_clean();
echo json_encode($resposta);
?>
still not understood how so I would have to put the walk starting from the form page ???
– JottaVideos
Is your server windows or linux? What folder are the PHP codes in? Example: /var/www/html/ or C: wamp www\
– Allan Andrade
c: xampp htdocs img server\
– JottaVideos
I did an update on the answer, test now tell me if it worked.
– Allan Andrade
Cara vc helped me a lot thanks, but now I’d like to know how I make it work on a web server. o 000.Webhost
– JottaVideos
@Jottavideos, if it worked, I ask you to choose my answer and mark it with +1. For the new question, create a new question and I’ll help you there (just send me the link).
– Allan Andrade