If you already have an exit in json_encode()
means that there has already been upload processing, it does not make much sense to recreate an upload form to send the same thing twice. Now what would make sense is to capture this JSON output in javascript rather than PHP because you have already submitted image processing in PHP and already have output in JSON, you agree.
If you want to treat within PHP and save some data before exiting in JSON, you need to find out where that output is json_encode($array_saida)
get that variable: $array_saida
, and find the $array_saida['name_file']
key before moving on to encode and save the data in the database.
However, I believe that you may be inside a form and want to load only the reference and display this image inside a form or something before executing the submission of a save form, however, there should be no co- % on this form.
The way to capture your JSON is just by returning the same ajax method that cropped this image and generated this JSON output. As I do not know your method, I'll give you an example of a return based on this API: link
$.ajax('/path/to/upload', {
method: "POST",
data: formData,
processData: false,
contentType: false,
success: function (data) {
var e = jQuery.parseJSON(data);
$('#sua_imagem').attr('src', e.url);
$('#img').val(e.name_file);
},
error: function () {
console.log('Ocorreu um erro no processo!');
}
});
And in your HTML form:
<form action="?salvar" method="post" name="salvamento">
<img src="undefined.jpg" id="sua_imagem" width="180" height="180" border="0">
<input type="hidden" id="img" name="imagem"><br>
<input type="submit" value="Enviar">
</form>