How to preview images in the form and transfer images to the server without reloading the page. I have the code for uploading pictures to the server and to the database, but this all goes with reloading the page. I would like to make a preview of the image and then upload the images to the server without rebooting. 1) file handler $ uploaddir = 'i /';
$apend=date('YmdHis').rand(100,1000).'.jpg'; $uploadfile = "$uploaddir$apend"; $fileName = $_FILES['userfile']['name']; if(($_FILES['userfile']['type'] == 'image/gif' || $_FILES['userfile']['type'] == 'image/jpeg' || $_FILES['userfile']['type'] == 'image/png') && ($_FILES['userfile']['size'] != 0 and $_FILES['userfile']['size']<=1024000)) { if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { $c="INSERT INTO images (name) VALUES('".$uploadfile."')"; $q=$dbh->prepare($c); $q->execute(); $size = getimagesize($uploadfile); if ($size[0] < 5001 && $size[1]<5001) { echo "Файл загружен. Путь к файлу: <b>http://led.remturbo.ru/".$uploadfile."</b>"; } else { echo "Загружаемое изображение превышает допустимые нормы (ширина не более - 500; высота не более 1500)"; unlink($uploadfile); } } else { echo "Файл не загружен, вернитеcь и попробуйте еще раз"; } } else { echo "Размер файла не должен превышать 5000Кб"; } 2) form
<html> <head> </head> <body> <form name="upload" action="load.php" method="POST" ENCTYPE="multipart/form-data"> Выберите файл для загрузки: <input type="file" name="userfile"> <input type="submit" name="upload" value="Загрузить"> </form> <? $stmt = $dbh->query('SELECT name FROM images'); while ($row = $stmt->fetch()) { ?><img style="height: 100px; width: 100px;" src="/<?= $row['name'] ?>"> <?} ?> <? if(isset($_POST['del'])) { unlink($uploadfile); } ?> </body> </html>