0

I have this code that helps me to open a file input when I click on an image:

HTML/PHP:
<label for="img-input">
  <img src=<?php echo "".$file[$n].""; ?> class="canvas-1">
  <div class="alert-success pad-top-bottom text-center"><strong><?php echo basename($file[$n]); ?></strong></div>
</label>
<input type="file" id="img-input">

where "$file[$n]" is the address of the file on the server folder. There is a bunch of image that are rendered on the screen and when I click on one them, the file input opens. That is ok. What I would like to do is that when I select a image from the file input by clicking on a specific image, The selected image should replace the image I clicked before.

I read many uploading solutions with JQuery but none provided the solution I wanted. Do someone know a way to handle that?

Thanks in advance.

Patrik
  • 351
  • 1
  • 4
  • 17
  • You can't have `move_uploaded_file` in javascript, because js is client-side script. You have to upload the new file to server and **then** replace old file with php code – fusion3k Feb 10 '16 at 16:08
  • Is there a way to embed php code in JQuery function and get it processed by PHP instead of JS to get it done server-side instead of client-side? – Patrik Feb 10 '16 at 16:26
  • I really don't know... but why? – fusion3k Feb 10 '16 at 16:31

1 Answers1

0

You should use only JS for changing preview of picture in page.

Like this

If you want it to also change on server side then you should use AJAX solution. This solution are more complex, but you can find a lot of tutorials in internet.

Community
  • 1
  • 1
Taras Budzyn
  • 160
  • 1
  • 7