41 responses to “PHP Tutorials Uploading Storing an Image inside a MySQL Database Part 2 YouTube”
ok so I had the cracked image problem, I kept trying till and I got it to work with this code, it's written in the same php file no need to make a get.php
IMPORTANT : staff.image is my database.table, just write your table name if u declared the database make sure you replace my variables with your correct ones, copy pasting the code won't work, you'll need to adjust with yours.
if ($image_size==FALSE) {
echo "Make sure you upload an image"; } else { if (!mysqli_query($conn,"INSERT INTO staff.image(`user`, `img`, `img_name`) VALUES('".$_SESSION['user']."', '$image', '$Img_Name')")) { echo "problem uploading image"; } else { $lastid = $_SESSION['user']; echo "Image uploaded.<p /> Your image:<p />";
when i add the header("Content-type: image/jpeg"); all i get is a square in the top left corner with no other content. not even my image. what am i doing wrong. All my code is the same from then on
If you have this: header("Content-type: image/jpeg"); can you only add jpeg files? or can you add more parameters like this: header("Content-type: image/jpeg","Content-type: image/png);
use longblob instead of blob, and write <img src='get.php?id=$lastid' /> instead of what he wrote (use ' before get and after $lastid). With that last thing it worked for me (longblob is if you use big big pictures )
im getting the broken image symbol, i have changed it to view the other information in the database, everything shows but the image, any ideas anyone??
there is something I dont understand ,, how come in your code you have header set for Content-type: image/jpeg but you use PNG image and still shows the image? 😐
If the image is not showing and you're just getting a broken image icon when you open the get.php file in your browser then it might be because you're including somthing in that document. So remove any include "document.php" from the get document. Also make sure you do not have AdBlock enabled as it will prevent you from loading an image from another page like we're doing here.
Hi… Kindly show how to display the records stored in the database with pagination. I mean on click on next button the next record set should get displayed. Thanks.
hi, first thank you for the video. I have a problem with the insertion request,, so when i click on submit button the condition pass by the echo "Error Uploading image" !!! what should i do ??
The showing a broken icon image was driving me MAD man, but I got it. I fixed two things. You need to try them both independently or together. First, I changed the header to header("Content-type: image/png"); instead of /jpeg. Secondly, on the get.php, I used the database id field as he did in this video "id" EXCEPT in my database, mine I called it 'IMG_ID" so make sure your database id name matches on the SELECT WHERE statement to whatever you called it. so I changed it from ("SELECT * FROM Member_IMAGE WHERE id='$id'"); TO ("SELECT * FROM Member_IMAGE WHERE IMG_ID='$id'"); It took me 4 hours to figure it out and hundreds of mistakes, but I have it working. Good luck.
for some reason this works only if I put directly link to get.php with image id specified, it doesn't show in index.php through scr, any suggestions? php.ini or apache config maybe?
THe other thing you HAVE to do is put "enctype="multipart/form-data"" in your form tag like so: <form enctype="multipart/form-data" action="index.php" method="POST">
It was driving me absolutely mad because i couldn't figure out what i was doing wrong until I read about that extra tag attribute you have to put in for newer versions of PHP. The other thing I changed in my script was when the database connection is established. You should only establish the connection once you know that the uploaded file is valid and is an image. I know its just a rough tutorial but i wanted to say something 😛 For the curious people who want to make their code more efficient.
Something wrong with the code. The img data is being stored in the database but a broken image logo in the output. I changed blob to longblob but still doesn't work.
Your other tutorials are great, but this one is not complete. Please take it down if you won't fix the tutorial because it does waste people's time and effort. But thanks for your other tutorials.
my images are not fully displaying. only like the fist 200px in width is displaying. I think its something to do with the file size. in the video his files were like 3.5kb mine are 64kb.
41 responses to “PHP Tutorials Uploading Storing an Image inside a MySQL Database Part 2 YouTube”
ok so I had the cracked image problem, I kept trying till and I got it to work with this code, it's written in the same php file no need to make a get.php
IMPORTANT : staff.image is my database.table, just write your table name if u declared the database
make sure you replace my variables with your correct ones, copy pasting the code won't work, you'll need to adjust with yours.
if ($image_size==FALSE)
{
echo "Make sure you upload an image";
}
else
{
if (!mysqli_query($conn,"INSERT INTO staff.image(`user`, `img`, `img_name`)
VALUES('".$_SESSION['user']."', '$image', '$Img_Name')"))
{
echo "problem uploading image";
}
else
{
$lastid = $_SESSION['user'];
echo "Image uploaded.<p /> Your image:<p />";
$image3 = "SELECT * FROM staff.image";
$r=mysqli_query($conn, $image3);
$row = mysqli_fetch_array($r);
echo '<img src="data:image/jpeg;base64,' . base64_encode( $row['img'] ) . '" />';
echo $row['img_name'];
}
}
I'm on YT most of the time so if anyone has any problems with their code just reply to my comment and I'll try to help as much as I can
mine is not working 🙁
it only show this.
C:xampptmpphp4D80.tmpPlease select an image
what version of xampp are you using anyway? please reply as soon as you read my comment. thank you very much!
why in my case it displays cracked image
when i add the header("Content-type: image/jpeg"); all i get is a square in the top left corner with no other content. not even my image. what am i doing wrong. All my code is the same from then on
not working for me man
If you have this: header("Content-type: image/jpeg"); can you only add jpeg files? or can you add more parameters like this: header("Content-type: image/jpeg","Content-type: image/png);
the image is inserted into the database but it is showing an image symbol not the image…i am trying to update actually..here is my code …
profile.php
<form action="profile.php" method="POST" enctype="multipart/form-data">
<h4><b>FILE</b></h4>
<input type="file" name="image">
<input type="submit" value="upload">
</form>
<?php
$file = $_FILES['image']['tmp_name'];
if(!isset($file))
echo "please select an image";
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 "that's not an image";
else
{
if(!$query = mysqli_query($mysqli,"UPDATE user SET profile = '".$image."' WHERE id = '".$_SESSION['user_id']."' "))
echo "problem uploading";
else
{
$lastid = $_SESSION['user_id'];
echo "image uploaded.<p> your image: </p><img src=get.php?id=$lastid>";
}
}
}
?>
get.php
<?php include("connect.php");
session_start();
$id = $_SESSION['user_id'];
$image = mysqli_query("SELECT * FROM user WHERE id='".$id."'");
$row = mysqli_fetch_array($image);
echo $row['image'];
?>
use longblob instead of blob, and write <img src='get.php?id=$lastid' /> instead of what he wrote (use ' before get and after $lastid). With that last thing it worked for me (longblob is if you use big big pictures )
it only shows half of the image. why is that? Is there a way I can make if full image size?
when im running mine it looks like this
File: Choose File Upload
Your image:
"; } } } ?>
and the image is not showing,
what am i gonna do? i really need it for our thesis can somebody help me please 🙁
thank you so much for this video .. it's clear
I do it step by step .. but finally the image is not appear .. what can I do !
where is directory that image who have uploads ?
YOU ARE THE BEST THANK YOU SO MUCH !!!!!
it is working but in the database it shows blob-0b in the image column..please help..
please come up with MP3 and Audio File upload Using PHP and MySql… in next tutorials… 🙂
this is the best way of learning from you… 🙂
Totally useless, not working for me. And why the code is not in video text field, so we can use the real code!!!
im getting the broken image symbol, i have changed it to view the other information in the database, everything shows but the image, any ideas anyone??
there is something I dont understand ,, how come in your code you have header set for Content-type: image/jpeg but you use PNG image and still shows the image? 😐
If the image is not showing and you're just getting a broken image icon when you open the get.php file in your browser then it might be because you're including somthing in that document. So remove any include "document.php" from the get document. Also make sure you do not have AdBlock enabled as it will prevent you from loading an image from another page like we're doing here.
Hi… Kindly show how to display the records stored in the database with pagination. I mean on click on next button the next record set should get displayed. Thanks.
and can u show me how to update image?
how to showing all of the image in database
Problem uploading image, please help.
With this I get an error uploading certain gifs and also I get an error when uploading .webms
hi, first thank you for the video.
I have a problem with the insertion request,, so when i click on submit button the condition pass by the echo "Error Uploading image" !!!
what should i do ??
The showing a broken icon image was driving me MAD man, but I got it. I fixed two things. You need to try them both independently or together. First, I changed the header to header("Content-type: image/png"); instead of /jpeg. Secondly, on the get.php, I used the database id field as he did in this video "id" EXCEPT in my database, mine I called it 'IMG_ID" so make sure your database id name matches on the SELECT WHERE statement to whatever you called it. so I changed it from ("SELECT * FROM Member_IMAGE WHERE id='$id'"); TO ("SELECT * FROM Member_IMAGE WHERE IMG_ID='$id'"); It took me 4 hours to figure it out and hundreds of mistakes, but I have it working. Good luck.
for some reason this works only if I put directly link to get.php with image id specified, it doesn't show in index.php through scr, any suggestions? php.ini or apache config maybe?
It wont add to the database!!..
I have a problem with the images not showing but i get the icon that there should be an image. could some1 help me ? PS: I used mysqli
THe other thing you HAVE to do is put "enctype="multipart/form-data"" in your form tag like so:
<form enctype="multipart/form-data" action="index.php" method="POST">
It was driving me absolutely mad because i couldn't figure out what i was doing wrong until I read about that extra tag attribute you have to put in for newer versions of PHP.
The other thing I changed in my script was when the database connection is established. You should only establish the connection once you know that the uploaded file is valid and is an image. I know its just a rough tutorial but i wanted to say something 😛 For the curious people who want to make their code more efficient.
Do not addslashes when inserting to database, that caused me lots of problems:O
can you add another video displaying all image inside database plssssss grant my request!
my dick is toooo big
Something wrong with the code. The img data is being stored in the database but a broken image logo in the output. I changed blob to longblob but still doesn't work.
Your other tutorials are great, but this one is not complete. Please take it down if you won't fix the tutorial because it does waste people's time and effort. But thanks for your other tutorials.
my images are not fully displaying. only like the fist 200px in width is displaying. I think its something to do with the file size. in the video his files were like 3.5kb mine are 64kb.
The image gets stored on the database, but doesn't show on the image tag, help?
Doesn't display my image. Followed tutorial to the letter. Says cannot display image because it contains errors.
my image is uploaded in database but not showing on the page..can someone help plz..
thnx in advance
Thanks for the tutorial !! ^^
For those who only have half an image showing:
http://stackoverflow.com/questions/409761/why-is-only-64kb-of-data-being-saved-in-my-mysql-data-column