Help with PHP

Amunette

New member
Hi everyone, I'm pretty new to this forum [MENTION=14824]Donisia[/MENTION] introduced me to it. I am a studying programming and need help with PHP :eek:... I have been coding a website, but,have struggled with displaying images from and sql database which is local on my machine.

Using the BLOB variable in the database and uploading the image, I'm having an,issue actually displaying it. Any ideas or help would be appreciated. Thank you :D
 
Are you saving the actual image data into the database? :wtf:

Most people would just save the image in a folder somewhere and save the path in the database.
 
Using a blob will help keep your filesystem clean, and reduce the chance of there being 'missing links' between image references and the image itself, but you will take a performance hit.

Are you sure you are storing the image correctly? Maybe show us the code you have for storage, and what you've tried for the displaying of the image.
 
You can store your images in your database, then your database will grow very quickly and database maintenance is more difficult than file system maintenance. For example, resizing an image on file system is "convert" while in a database there are a few steps required.

If I could choose between having a clean DB or clean file system, I would MUCH rather take the clean database.
 
If I could choose between having a clean DB or clean file system, I would MUCH rather take the clean database.

Yup, any day! Its easy enough to whip up a perl script to grab all the filenames/paths from the database and find out if anything is missing... Back at my old job, we had some developer using tomcat to serve up images. I told him to take them out of the jar files and drop them somewhere apache could serve them. He said it shouldn't make a difference, but the clients were all complaining about performance. I told the developer to use the service that is optimized for serving images, and let tomcat run the code...
 
Have a client who loaded 130 Gigs worth of PDFs into his database. Then he extracted these to actual files, and started the linking in the database rather than having them in the database. Then he quit the development company, and nobody else there knows what is going on. Now we are sitting with 130 + 130 Gigs of data of which one or the other is not necessary. And nobody knows what is going on. Sigh.....

Anyway....

You can lead a client to the water, but you are not allowed to drown him.
 
I am trying to get the image to display on the actual website and have coded it in two ways:

-echo $row['picture'];
-echo '<img src="images'.'picture'.'" />' (gotten from the internet)

The first will show random text e.g. (‰PNG IHDR,,ö" =iCCPiccxڝSgTSé=÷ÞôBKˆ), the second just inserts a tiny little thumbnail of a broken picture.

I unfortunately cannot show you my SQL database.
But it consists of a name (varchar), picture (blob), description (mediumtext), price (double), genre (varchar), id (int)
 
Last edited:
I am trying to get the image to display on the actual website and have coded it in two ways:

-echo $row['picture'];
-echo '<img src="images'.'picture'.'" />' (gotten from the internet)

The first will show random text e.g. (‰PNG IHDR,,ö" =iCCPiccxڝSgTSé=÷ÞôBKˆ), the second just inserts a tiny little thumbnail of a broken picture.

I unfortunately cannot show you my SQL database.
But it consists of a name (varchar), picture (blob), description (mediumtext), price (double), genre (varchar), id (int)

You can't print out the raw image like that. Either do it inline:

echo '<img src="data:image/png;base64,' . base64_encode($row['picture']) . '" />';

Or what would be better, is calling a PHP function to parse it:

function showImage($rawImage, $imageType='image/png') {
header('Content-Length: ' . strlen($rawImage));
header('Content-Type: ' . $imageType);

echo $rawImage;
}

showImage($row['picture']);

I've assumed you're dealing with png's only. You'd then call a function via url that will load the image data and pass it to showImage. So something like: /showimage.php

<img src="/showimage.php" />
 
Thank you so much, will have a look. I appreciate the help and it absolutely worked! Finally :D
 
Last edited:
Back
Top