How do I upload photos to a mysql database using php and I again reproduce an image from the database and displayed in the browser

3 Years
Discussion Span
Last Post by Ryan_12

You haven't posted any code so I don't really wan't to write any for you.. however I will pseudo for you :)

You can use simple PHP to store an uploaded image in your webserver and whilst doing that, record the name of the image stored and the file type etc... in a mysql database.

From what I understand, there is no way to physically store an image in the MySQL database itself


it is called BLOb or binary large object. Yes, you can store images as BLOb in the database.

You just have to show us what've got so far. Writing it is pretty easy, but I need see how motivated you are in doing this.

Edited by veedeoo: info added.


Thanks for clearing that up! I never knew you could use that, thank you :)

But would my method still be a suitable method to use?

Votes + Comments
I don't know what you want

My most preferred in storing images is exactly the same as you have suggested.

Some people prefer to store images in the database. Used to be, images of high value e.g. photographers will store their porfolio in mysql after the copyright has been injected into the image, rather than just creating a layer over them and save in the directory.

Others may have a really good reason in doing so.


Like we said above, you have to show us that you've tried to do this yourself so we are not giving away code to a script kiddie.

I really want to help you, but you have to show us you've tried




$dir= dirname(__FILE__) ."/uploads/";

$path  = $_FILES ['fileToUpload'] ['tmp_name'];
$name  = $_FILES ['fileToUpload'] ['name'];
$size  = $_FILES ['fileToUpload'] ['size'];
$error = $_FILES ['fileToUpload'] ['error'];
$type  = $_FILES ['fileToUpload'] ['type'];

if (!empty($name)) {

echo "Uploaded !";

} else {
  echo "error !";


<form action="upload.php" method="post" enctype="multipart/form-data">

<!-- input file -->
<input type="file" name="fileToUpload" id="fileToUpload" onchange="fileSelected();" />
<input type="submit" name="submit" id="submit" />


I want to explain how the files are stored in a folder uploads and files are displayed in view.php page


I really can't understand what you're getting at here :(

Where is the view.php file? First you would need to store the file in a specified path..

Then in the view.php file you will probably have to open the file from that path, which you could do straight in the file or from a form.. I'm not sure still on what you're trying to achieve

EDIT: I wouldn't copy a whole tutorial either if I was you, it doesn't help anyone..

Edited by Ryan_12

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.