No form and no Submit button
index.html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id='ads-files-edit' type='file' accept='image/*' placeholder='Selecione a imagem' data-max-size='5242880' class='form-control form-group-lg ads-files-edit'>
<script language="javascript">
$(document).ready(function() {
$('#ads-files-edit').change(function(){
var file_data = $('#ads-files-edit').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: "upload-imagem.php",
type: "POST",
data: form_data,
contentType: false,
cache: false,
processData:false,
success: function(data){
$("#result").html(data);
}
});
});
})
</script>
<div id="result"></div>
upload-image.php
<?php
$userFile=$_FILES['file'];
$name = $userFile['name'];
$tmp = $userFile ['tmp_name'];
if(empty($userFile)):
echo '<a href="uploadFoto.htm">Selecione um arquivo para fazer upload</a>';
else:
if(move_uploaded_file($tmp, 'uploads/'.$name)):
echo 'Arquivo enviado com sucesso';
else:
echo 'Error';
endif;
endif;
?>
The absence of an element
<form>
is a semantic error (only a warning). I’m not sure, but I think this is not possible, a while ago I tried to use jQuery to download a PDF but it didn’t work because the Blob type is not supported by the AJAX part of the library– Costamilam
https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252
https://i.stack.Imgur.com/evLUR.png
– user60252
Thank you all for your cooperation.
– AngeloJ