Echo1 Posted June 14, 2015 Share Posted June 14, 2015 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) Quote Link to comment https://forums.phpfreaks.com/topic/296801-image-upload-and-show-on-indexphp-php-mysql/ Share on other sites More sharing options...
Barand Posted June 14, 2015 Share Posted June 14, 2015 First of all, why do you need to manipulate the image and not display image as it is stored? Quote Link to comment https://forums.phpfreaks.com/topic/296801-image-upload-and-show-on-indexphp-php-mysql/#findComment-1513831 Share on other sites More sharing options...
Echo1 Posted June 15, 2015 Author Share Posted June 15, 2015 (edited) Because i want something like this: (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 June 15, 2015 by Echo1 Quote Link to comment https://forums.phpfreaks.com/topic/296801-image-upload-and-show-on-indexphp-php-mysql/#findComment-1513877 Share on other sites More sharing options...
Ch0cu3r Posted June 15, 2015 Share Posted June 15, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/296801-image-upload-and-show-on-indexphp-php-mysql/#findComment-1513880 Share on other sites More sharing options...
ricpurcell Posted June 17, 2015 Share Posted June 17, 2015 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 Ch0cu3ruse $result = $mysqli->query('SELECT image,id FROM images'); while($row = $result->fetch_assoc()) { echo '<img src="' . $row['image'] . '" alt="'. $row['image_id']. '" />'; // output image } Quote Link to comment https://forums.phpfreaks.com/topic/296801-image-upload-and-show-on-indexphp-php-mysql/#findComment-1514195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.