Jump to content

how to make blob type file shown as image in web page and downloadble after click?


Recommended Posts

input

<form action=" " method="post" enctype="multipart/form-data">
				<div class="modal-body">
						<div class="form-group">
							<label class="form-control-label">Contractor's Company Name :</label>
							<input type="text" name="companyname" class="form-control"/><br><br>
							<input type="hidden" name="email" value="<?php echo $_SESSION['email']?>">
							<label class="form-control-label">Responsible Person's Name :</label>
							<input type="text" name="responsiblename" class="form-control">
						</div>
						<div class="form-group">
							<label>Fit Out Description :</label>
							<textarea name="editor1" class="form-control"></textarea>
						</div>
						<div class="form-group">
							<label>Photos :</label>
							<input type="file" name="photos"/>
							<p style="color: red">Ekstensi yang diperbolehkan .png | .jpg | .jpeg | .gif</p>
						</div>
				</div>
				<div class="modal-footer">
					By clicking apply you are agree to all terms and condition mentioned above &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
					<button class="btn btn-danger" style="border-radius:0%;" data-dismiss="modal">Close</button>
					<input type="submit" class="btn btn-success" style="border-radius:0%;" name="apply"  value="Apply">
				</div>
			</form>

process

<?php
	if (isset($_POST['apply'])){
		$email=$_SESSION['email'];
		$companyname = $_POST['companyname'];
		$responsiblename = $_POST['responsiblename'];
		$description = $_POST['editor1'];
		$photos = file_get_contents($_FILES['photos']['tmp_name']);
		$sql = "INSERT INTO leaves(email,companyname,responsiblename,description,photos)VALUES('$email','$companyname','$responsiblename','$description','$photos') ";
		$run = mysqli_query($con,$sql);
		if($run == true)
		{
			echo "<script> 
					alert('Entering Items Requested, Please Wait For 'Approved' Status');
					window.open('dashboard.php','_self');
				  </script>";
		}
		else
		{
			echo "<script> 
			alert('Failed To Apply');
			</script>";
		}			
	}
 ?>

output

<tbody>
							 	<?php 
									$sql = "SELECT * FROM leaves WHERE email='".$_SESSION['email']."'";
									$que = mysqli_query($con,$sql);
									$cnt=1;
									while ($result = mysqli_fetch_assoc($que)) {
										
								?>									
							 	<tr>
									<td><?php echo $cnt;?></td>
									<td><?php echo $result['email'];?> </td>
							 		<td><?php echo $result['companyname']; ?></td>
							 		<td><?php echo $result['responsiblename']; ?></td>
							 		<td><?php echo $result['description']; ?></td>
							 		<td><?php echo '<img src="data:image/jpg;base64,'.base64_encode($result['photos']).'" />';?></td>
							 		<td>
							 			<?php 
							 			if ($result['status'] == 0) {
							 				echo "<span[$cnt] class='badge badge-warning'>Pending</span>";
							 			}
							 			else{
							 				echo "<span class='badge badge-success'>Approved</span>";
							 			}
							 	$cnt++;	}
							 		 ?>
							 		</td>
							 	</tr>
							 </tbody>

what I want:

the blob file type shown as image in web page and downloadble after click.Table contains: email,company name, responsible name,description, photos, and status.Column photos are setted within longblob type. the insert already sucessfull, but the output in web page shown crashed image block. maybe something wrong within base64_encode?

 

This 'blob' thing.  Are you saying that you are placing image files into a db table?  Why?   It is much better to save those types of files as their own files in a designated folder rather than having to store and retrieve them thru a db interface.  Simply save the file's name in the table and use whatever your regular files path to locate it when you need it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.