Multiple image upload to database and display from it

Upload image into the database and retrieve from it

Video: Multiple image upload and display from database

Create the database name as 'image' and just copy this table given below

Database
CREATE TABLE IF NOT EXISTS `multiple` ( `id` int(255) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `image` longblob NOT NULL, PRIMARY KEY (`id`) )

Html: In this form tag make sure that you set the '[ ]' in the input tag and 'multiple' use to select the multiple image
<form action="#" enctype="multipart/form-data" method="post"> <input multiple="" name="img[]" type="file" /> <input name="submit" type="submit" /> </form>

PHP: (upload and display)
mysql_connect("localhost","root","");mysql_select_dB("image");if(isset($_POST["submit"])){$filename = $_FILES['img']['name']; $file_tmp = $_FILES['img']['tmp_name']; $filetype = $_FILES['img']['type']; $filesize = $_FILES['img']['size']; for($i=0; $i<=count($file_tmp); $i++){ if(!empty($file_tmp[$i])){ $name = addslashes($filename[$i]); $temp = addslashes(file_get_contents($file_tmp[$i])); if(mysql_query("Insert into multiple(name,image) values('$name','$temp')")){ } else{ echo "failed"; echo "<br />"; } } } } $res = mysql_query("SELECT * FROM multiple"); while($row = mysql_fetch_array($res)){ $displ = $row['image']; // please place the single quotation ' instead &#39; echo '<img src="data:image/jpeg;base64,&#39;.base64_encode($displ).&#39;" />'; echo "<br />"; }

Comments

  1. Thanks for Sharing an Information to us . If Someone wants to know about Digital Marketing Course and Web Development Courses. I think this is the right place for you.
    SEO Courses in coimbatore and Digital Marketing Courses in Coimbatore

    ReplyDelete
  2. hi thank you for your code.. but i got this error mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\web\imageview.php on line 33

    ReplyDelete

Post a Comment

Popular posts from this blog

PHP Login and Registration script

String methods in java