Preview image using AJAX in PHP

How do I create a preview of an image to upload before it is actually submitted using AJAX in PHP?

+4
source share
3 answers

Without loading the image, this will not be possible in JavaScript, as far as I can see, since security restrictions will prevent you from defining the selected file when loading the file and pasting this file in img (as it was possible five years ago.)

You will be more fortunate with Flash-based downloaders. I have seen some that offer the features you want.

Update: Here , which offers a preview function. From what I see, base64 encodes a local image and feeds it to an adjacent HTML page as an embedded <img> . This is great because it can integrate well into your site. However, it does not work with any version of Internet Explorer.

Here's a fully Flash-based solution that scans in all browsers.

+1
source

First you need to upload the document to the server. How can you show it.

 <img src="uploads/file1_12224.jpg" /> 
0
source

The input type "file" does not reveal the local file location of the file being uploaded. It "appears" because as a user you can see the location, but the web page never knows this value. Without a local address file, you cannot show a preview image on a web page using simple HTML or JavaScript.

0
source

Source: https://habr.com/ru/post/1303922/


All Articles