If you already have a way out in json_encode()
means there’s already been an upload processing, it doesn’t 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 and not in PHP, as you have already sent the image processing in PHP and already have the output in JSON, agree.
In case you want to handle inside PHP and save some data before exit in JSON, you need to find where this output is json_encode($array_saida)
take this variable: $array_saida
, and locate the key $array_saida['name_file']
before moving to Find and save the data in the database.
However, I believe that maybe you are inside a form and want to load only the reference and display this image within a form or something before performing the submission of a save form, still, there should be no enctype="multipart/form-data"
on this form.
The way to capture your JSON is precisely by returning the same ajax method that made Crop of this image and generated this JSON output. As I don’t know your method I’ll give an example of return, based on this API: https://github.com/fengyuanchen/cropper
$.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>
You can post the Form HTML code?
– Diogo
@Diogo I’ve already edited
– pc_oc
From what I see the file "img_crop_to_file.php" is what returns the JSON response. Why not store in the database at this time ?
– Diogo
@Diogo, I’m only interested in keeping it when I create the record, unless I put it in a temporary table.
– pc_oc
@pc_oc, where the javascript code that makes the image post?
– Ivan Ferrer
From what I see, you don’t need to make a form with
enctype="multipart/form-data"
because the image has already been published via ajax. When you did Crop. What you need to do is just publish the image path in the bank.– Ivan Ferrer
None of the answers answers your question?
– durtto