Jump to content

Recommended Posts

Im newbie in PHP and im working on mini project, image blog

 

So, I created all, but now only problems is inserting image into database then with image ID showing in index.php (homepage) 

 

Something like this for image showing

 

<img src="image.php?id=<?php echo $row['image_id']; ?>" title="myimage">

 

I dont know how to do that, if someone can give me some way, i'm tried all what I know but did not successful

 

(Btw. I have upload script, only problem in that script is inserting in db)

 

 

 

Because i want something like this:

1434350925-Untitled.png

(There is more pages, 1,2,3,4,5....)

 

When in administration panel upload new image, then that uploaded image get ID and automatic show on index.php (homepage)

 

Its like a some text blog, just with a image if you know what I mean

Edited by Echo1

I think Barands argument is why is the physical image being (its binary contents) being stored in the database? This adds a unnecessary layer of complication.

 

Uploaded images should be stored on the servers file system. What gets added to the database should only be the images filename (or the file path for where the image is stored on the server) added to your database. That way all you need to do to show the image is output the filename (or filepath) in the <img /> tag src attribute. Eg

$result = $mysqli->query('SELECT image FROM images');
while($row = $result->fetch_assoc())
{
    echo '<img src="' . $row['image'] . '" />'; // output image
}

With your current setup because the binary contents of the image is stored in the database, you have to pass the id of the image to an external php script, set the appropriate headers for the image, then query the database to get the binary contents of the image and finally echo the binary contents.

 

I would suggest you alter your upload script to only store the image filename/path in the database.

I have just created something similar but my images are stored in a directory and the filename is fetched from sql as this is better than to have a blob of images i think i understand what you are trying to do and in order to do this  i agree with Ch0cu3r

use

$result = $mysqli->query('SELECT image,id FROM images');
while($row = $result->fetch_assoc())
{
    echo '<img src="' . $row['image'] . '" alt="'. $row['image_id']. '" />'; // output image
}
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.