Search database image in php

Asked

Viewed 33 times

1

inserir a descrição da imagem aquiGood morning People regarding the code I am trying to get an image that is in the bank and bring to the page, but it is not bringing the image(Consultation of patient registration). For the inclusion of the patient registration with the photo, I am using the code below that is working right, but if I want to consult a record that has an image, what is wrong with the code below ? On the estate defaultPreviewContent the variable is being used $path is the one that contains the directory + file name.. I’m not sure I’m making myself clear. I’ll be waiting for you. Roger

<script type="text/javascript">
                            var btnCust = '<button type="button" class="btn btn-default" title="Add picture tags" ' + 
                              'onclick="alert(\'Call your custom code here.\')">' +
                              '<i class="glyphicon glyphicon-tag"></i>' +
                              '</button>'; 
                          $("#avatar-2").fileinput({

                            overwriteInitial: true,
                            maxFileSize: 1500,
                            showClose: false,
                            showCaption: false,
                            showBrowse: false,
                            browseOnZoneClick: true,
                            removeLabel: '',
                            removeIcon: '<i class="glyphicon glyphicon-remove"></i>',
                            removeTitle: 'Cancel or reset changes',
                            elErrorContainer: '#kv-avatar-errors-2',
                            msgErrorClass: 'alert alert-block alert-danger',
                            defaultPreviewContent:  '<img src= $path alt="Your Avatar" style="width:160px"> <h6 class="text-muted">Click para selecionar</h6>',  
                            layoutTemplates: {main2: '{preview} ' +  ' {remove} {browse}'},
                            allowedFileExtensions: ["jpg", "png", "gif"]

inserir a descrição da imagem aqui

  • could edit your question and add the code in writing? stackoverflow has the option to format the text as code

  • Oops, good morning. OK I edited the code, I don’t know if Oce understood ? Thank you

  • that $path is returning something?

  • Yes, it is returning the directory + the file name

  • It is returning as follows: .. /img_cad_patient/4bb77467d1b8a75a05bdbb8bc1b14d4a.jpg

  • concatenate the server url with the path from where the image is, meuservidor.com/img_cad_patient/4bb77467d1b8a75a05bdbb8bc1b14d4a.jpg for example

  • But it’s local, my machine, it’s still in development...

  • or it would look like this: 127.0.0.1/img_cad_patient/4bb77467d1b8a75a05bdbb8bc1b14d4a.jpg, this ?

  • yes, as long as the image path is inside the application server.

Show 4 more comments

1 answer

1


How are you passing the $path in a javascript code, you will have to open php inside the code, otherwise it will display $path instead of the contents of the variable.

What needs to be changed:

defaultPreviewContent: '<?='<img src="'.$path.'" alt="Your Avatar" style="width:160px"> <h6 class="text-muted">Click para selecionar</h6>'?>'
  • According to your orientation, I did so: defaultPreviewContent: <?='<img src="'. $path. '" alt="Your Avatar" style="width:160px"> <H6 class="text-muted">Click to select</H6>'? >, but it didn’t work, it just didn’t bring the image

  • As for the $path variable, it looks like this: $path = ".. /img_cad_patient/". $archiveFoto;

  • has tried to pass the ../img_cad_patient/4bb77467d1b8a75a05bdbb8bc1b14d4a.jpg fixed in the code?

  • Yes, I tried and then the image comes.... Strange right...

  • it does not show any error in browser F12?

  • What do you mean F12 ? I don’t understand... the inspecting elements ? If that’s it, I’ll see it now...

  • when you right-click on the page and select "Inspect"

  • Opa, sim vi agora, está reportando o seguinte erro:Uncaught Syntaxerror: Unexpected token <

  • could add a print with the bug, right after your code?

  • Hi put the image.. But the image was on top of the code, it was bad. I’m not used to using stackoverflow...

  • In the case the code I am putting like this: defaultPreviewContent: <?='<img src="'. $path. '" alt="Your Avatar" style="width:160px"> <H6 class="text-muted">Click to select</H6>'?>,

  • right in front of the bug Uncaught SyntaxError: Unexpected token < click where it is written patient-edit-form.php?id=31:423, probably the error will appear in more detail

  • Sure, but I can’t identify..

  • I made a small change to the code, try to put it this way: defaultPreviewContent: '<?='<img src="'.$path.'" alt="Your Avatar" style="width:160px"> <h6 class="text-muted">Click para selecionar</h6>'?>'

  • Bingo... solved.. Thank you very much. Thank you very much indeed....

  • For nothing, if you have how to define my answer as correct I would be grateful, since the problem has been solved :)

  • Taking advantage: Can you tell me how to bring in a Select component of html the records that are in PHP ? In fact, I know how to bring, but how can I bring only what was saved in the bank and even select others.

  • And how can I put it here that your answer is correct ?

  • creates another html select-related question, explaining what you need and how your database and page I help you with. Go to this link here to see how to mark the answer as correct

Show 14 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.