How to display or view the downloaded image after uploading to PHP without saving the database?

My project actually has 2 pages. The first page is a form that represents the loaded image on the 2nd page based on action="2page.php" , and will display and view the image. It should work on a client server, which means not including a database that stores the image file in it and extracting the specific image back to the page that I want to execute. In fact, I wrote a PHP script as follows: <?php echo $_GET[image]; ?> <?php echo $_GET[image]; ?> to display the uploaded image in the second but that didn't work.

+4
source share
4 answers

if your goal is to upload an image and save it in a directory on the server, then this code example can help you get started (although I will not swear that this is a mistake or is not safe). This is one page for loading, saving and displaying images.

 <?php // prevent timezone warnings date_default_timezone_set('America/New_York'); // set the upload location $UPLOADDIR = "images/"; // if the form has been submitted then save and display the image(s) if(isset($_POST['Submit'])){ // loop through the uploaded files foreach ($_FILES as $key => $value){ $image_tmp = $value['tmp_name']; $image = $value['name']; $image_file = "{$UPLOADDIR}{$image}"; // move the file to the permanent location if(move_uploaded_file($image_tmp,$image_file)){ echo <<<HEREDOC <div style="float:left;margin-right:10px"> <img src="{$image_file}" alt="file not found" /></br> </div> HEREDOC; } else{ echo "<h1>image file upload failed, image too big after compression</h1>"; } } } else{ ?> <form name='newad' method='post' enctype='multipart/form-data' action=''> <table> <tr> <td><input type='file' name='image'></td> </tr> <tr> <td><input name='Submit' type='submit' value='Upload image'></td> </tr> </table> </form> <?php } ?> 
+1
source

send the file to php script using jQuery and return the name and temp path to jQuery and put the response on <img> , and then, if the user clicks any button, paste this temporary image into your database using the new jQuery $.post() to another PHP script so that one php can get the file, and the other - paste it into your db

This link will help you send files using AJAX or jQuery

0
source

You just saved the file in your database whenever you want. When downloaded, the file will be saved in your temporary directory. From there, you will need to specify php to move it to the real directory using move_uploaded_file () .

0
source

you can try this ... first you can upload the file and then take two divs in html, one for the download button and the other for the image you see wana ... you can give the background color for better clarity and understanding.

  <?php $submit=$_POST['sub']; if(isset($submit)) { $name=$_FILES['img']['name']; $type=$_FILES['img']['type']; $size=($_FILES['img']['size'])/1024; $ext=end(explode('.',$name)); if (($ext == "gif") || ($ext == "jpeg") || ($ext == "jpg") || ($ext =="png") && ($size > 30)) { ##############################File Renaming ################################################### $newname=uniqid(); //$ext=end(explode('.',$name)); $fullname=$newname.".".$ext; $target="pics/"; $fulltarget=$target.$fullname; if(move_uploaded_file($_FILES['img']['tmp_name'],$fulltarget)) { echo "Success"; } else { echo "Failed"; } ##############################File Renaming end ################################################### } else{ echo "not successful"; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" type="text/css" href="abhi.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <div id="a1"> <form name="frm" method="post" enctype="multipart/form-data"> <input type="file" name="img" /><br /> <input type="submit" name="sub" value="Store" /> </form> </div> <div id="a2"> <?php echo "<img src='$fulltarget'>";?> </div> </body> </html> 
0
source

All Articles