php - How to display all blobs (images) form database -
ok uploaded images code below dont know how display it, want make gallery want display images on 1 page, if explain helpfull too!
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "phplogin"; $connect = mysqli_connect($servername,$username,$password,$dbname); $file = $_files['image']['tmp_name']; $ime = $_post['ime']; if(!isset($file)) { echo "izaberite sliku"; } else { $image = addslashes(file_get_contents($_files['image']['tmp_name'])); $image_name = addslashes($_files['image']['name']); $image_size = getimagesize($_files['image']['tmp_name']); if($image_size == false) { echo "niste izabrali dobru sliku"; } else { if(!$insert = mysqli_query($connect,"insert store values ('','$image_name','$image','$ime')")) { echo "problem sa postavljanjem slike"; } else { //$lastid = mysqli_insert_id($connect); // want display images here //echo "image uploaded.<p />slika:<p /><img src=get.php>"; } } }
?>
this code image display last id , dont know how make display images
<?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("databaseimage") or die(mysql_error()); $id = addslashes($_request['id']); $image = mysql_query("select * store id=$id"); $image = mysql_fetch_assoc($image); $image = $image['image']; header("content-type: image/jpeg"); echo $image;
?>
save images files instead of blobs. store url image in db varchar
the html
<form role="form" class="form-inline" enctype="multipart/form-data" method="post" action=""> <div class="form-group"> <input type="file" class="form-control" name="image"/> </div>
<input type="submit" name="upload" class="btn btn-success" value="upload" /> </form>
php
define('upload_path','images/');
this constant path of images. in case folder named images in same directory script working on
$errors = array(); function output_errors($errors){ $output=array(); foreach($errors $error){ $output[]='<li>'.$error.'</li>'; } return '<ul>'.implode('',$output).'</ul>'; } if(isset($_post['upload'])){ if(!empty($_files['image']['name'])){ $image=$_files['image']['name']; $image_type=$_files['image']['type']; $image_size=$_files['image']['size']; if((($image_type=='image/gif') || ($image_type=='image/jpeg') || ($image_type=='image/png') || ($image_type=='image/pjpeg')) && ($image_size>0) /*&& ($image_size<=max_file_size)*/){ if($_files['image']['error']==0){ /*give each image unique name*/ $image=microtime().$image; /*move uploaded file permanent folder*/ $target=upload_path.$image; if(move_uploaded_file($_files['image']['tmp_name'],$target)){ if(mysqli_query($connect,"insert images(`image`) values ('$image')") ){ $message="image uploaded sucessfully"; }else{ $errors[]="error,image not uploaded successfully"; /*delete permanent file server*/ @unlink(upload_path.$image); } }/*end of move uploaded file*/ } }else{ $errors[]="file uploaded must of type png, jpeg or gif"; /*delete temporary image file*/ @unlink($_files['image']['tmp_name']); }/*end of image validation*/ }else{ $errors[]="please select image file"; }/*empty*/ } if(!empty($errors))echo output_errors($errors); if(!empty($message)) echo $message;
your images table appear this
create table if not exists `images` ( `image_id` int(11) not null, `image` varchar(255) not null ) engine=innodb auto_increment=26 default charset=latin1;
to image db, have query selects image
table images. display image in html do
$queryimage=mysqli_query($connect,"select `image` images"); while($rowimage=mysqli_fetch_assoc($queryimage)){?> <img src="<?php echo upload_path.$rowimage['image'] ;?>" style="width:250px; height:200px"/> <?php }/*end of while loop getting images*/?>
Comments
Post a Comment