473,785 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Load multiple pictures into MySQL?

I'm trying to create a picture database for a site that I'm working on and I
would like to do the following:
- (main goal) Have a php script load an entire directory of photos into my
mysql database in one swoop.
- Display thumbnails on a general viewing page.
- allow for viewing individual pictures by clicking on the thumbnails.

<?php
error_reporting (E_ALL);
$id = $_REQUEST["iid"];
$link = mysql_connect(" localhost", "root", "") or die("Could not connect:
" . mysql_error());

mysql_select_db ("mysql") or die(mysql_error ());
$sql = "SELECT b1 FROM t1 where id in (1,2,3)";

$result = mysql_query("$s ql") or die("Invalid query: " . mysql_error());
header("Content-type: image/jpeg");

while ($row = mysql_fetch_arr ay($result))
{
$fileContent = $row['b1'];

$im = imagecreatefrom string($fileCon tent);
$width = imagesx($im);
$height = imagesy($im);
$imgw = 50;
$imgh = $height / $width * $imgw;
$thumb = ImageCreate($im gw,$imgh);

ImageCopyResize d($thumb,$im,0, 0,0,0,$imgw,$im gh,ImageSX($im) ,ImageSY($im));
ImagejpeG($thum b);

imagedestroy ($im);
imagedestroy ($thumb);
mysql_close ($link);
}
?>

It is only displaying one image.

Thanks
M.
Jul 25 '06 #1
3 4735
Michael martin wrote:
I'm trying to create a picture database for a site that I'm working on and I
would like to do the following:
- (main goal) Have a php script load an entire directory of photos into my
mysql database in one swoop.
- Display thumbnails on a general viewing page.
- allow for viewing individual pictures by clicking on the thumbnails.

<?php
error_reporting (E_ALL);
$id = $_REQUEST["iid"];
$link = mysql_connect(" localhost", "root", "") or die("Could not connect:
" . mysql_error());

mysql_select_db ("mysql") or die(mysql_error ());
$sql = "SELECT b1 FROM t1 where id in (1,2,3)";

$result = mysql_query("$s ql") or die("Invalid query: " . mysql_error());
header("Content-type: image/jpeg");

while ($row = mysql_fetch_arr ay($result))
{
$fileContent = $row['b1'];

$im = imagecreatefrom string($fileCon tent);
$width = imagesx($im);
$height = imagesy($im);
$imgw = 50;
$imgh = $height / $width * $imgw;
$thumb = ImageCreate($im gw,$imgh);

ImageCopyResize d($thumb,$im,0, 0,0,0,$imgw,$im gh,ImageSX($im) ,ImageSY($im));
ImagejpeG($thum b);

imagedestroy ($im);
imagedestroy ($thumb);
mysql_close ($link);
}
?>

It is only displaying one image.

Thanks
M.

You can't do it this way. The content-type header indicates a single
image will be generated.

You can split this into 2 files - the first one gets the rows and calls
the second once for each row to display the jpeg.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jul 25 '06 #2
Not sure on how to do that as I am new to PHP.

m.

"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:u8******** *************** *******@comcast .com...
Michael martin wrote:
>I'm trying to create a picture database for a site that I'm working on
and I would like to do the following:
- (main goal) Have a php script load an entire directory of photos into
my mysql database in one swoop.
- Display thumbnails on a general viewing page.
- allow for viewing individual pictures by clicking on the thumbnails.

<?php
error_reporting (E_ALL);
$id = $_REQUEST["iid"];
$link = mysql_connect(" localhost", "root", "") or die("Could not
connect: " . mysql_error());

mysql_select_db ("mysql") or die(mysql_error ());
$sql = "SELECT b1 FROM t1 where id in (1,2,3)";

$result = mysql_query("$s ql") or die("Invalid query: " .
mysql_error()) ;
header("Content-type: image/jpeg");

while ($row = mysql_fetch_arr ay($result))
{
$fileContent = $row['b1'];

$im = imagecreatefrom string($fileCon tent);
$width = imagesx($im);
$height = imagesy($im);
$imgw = 50;
$imgh = $height / $width * $imgw;
$thumb = ImageCreate($im gw,$imgh);
ImageCopyResiz ed($thumb,$im,0 ,0,0,0,$imgw,$i mgh,ImageSX($im ),ImageSY($im)) ;
ImagejpeG($thum b);

imagedestroy ($im);
imagedestroy ($thumb);
mysql_close ($link);
}
?>

It is only displaying one image.

Thanks
M.

You can't do it this way. The content-type header indicates a single
image will be generated.

You can split this into 2 files - the first one gets the rows and calls
the second once for each row to display the jpeg.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jul 25 '06 #3
Michael Martin wrote:
Not sure on how to do that as I am new to PHP.

m.

"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:u8******** *************** *******@comcast .com...
>>Michael martin wrote:
>>>I'm trying to create a picture database for a site that I'm working on
and I would like to do the following:
- (main goal) Have a php script load an entire directory of photos into
my mysql database in one swoop.
- Display thumbnails on a general viewing page.
- allow for viewing individual pictures by clicking on the thumbnails.

<?php
error_reporting (E_ALL);
$id = $_REQUEST["iid"];
$link = mysql_connect(" localhost", "root", "") or die("Could not
connect: " . mysql_error());

mysql_select_db ("mysql") or die(mysql_error ());
$sql = "SELECT b1 FROM t1 where id in (1,2,3)";

$result = mysql_query("$s ql") or die("Invalid query: " .
mysql_error( ));
header("Content-type: image/jpeg");

while ($row = mysql_fetch_arr ay($result))
{
$fileContent = $row['b1'];

$im = imagecreatefrom string($fileCon tent);
$width = imagesx($im);
$height = imagesy($im);
$imgw = 50;
$imgh = $height / $width * $imgw;
$thumb = ImageCreate($im gw,$imgh);
ImageCopyRes ized($thumb,$im ,0,0,0,0,$imgw, $imgh,ImageSX($ im),ImageSY($im ));
ImagejpeG($thum b);

imagedestroy ($im);
imagedestroy ($thumb);
mysql_close ($link);
}
?>

It is only displaying one image.

Thanks
M.

You can't do it this way. The content-type header indicates a single
image will be generated.

You can split this into 2 files - the first one gets the rows and calls
the second once for each row to display the jpeg.
The first file contains all the sql code. It gets the data from the
database and generates an <img...attribut e in the HTML. This
attribute as the second file as its src and passes the filename of the
image being displayed to the second file.

The second file does all the work needed to create images. You probably
pulled the code you have out of a similar file. It gets I generates the
content header and all the image stuff itself. It knows which image to
use from the passed parameter.

Does this help with the process? Also, please don't top post.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jul 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1928
by: Peter Bach | last post by:
Would a medium sized (~500 pages) database driven website, search engine and mailing list be too much for one MySQL database? Instead of making using different databases I would use different tables. I would use PHP for all of this. Any help would be greatly appreciated.
0
2031
by: JakeC | last post by:
Hey all, I'm currently redesigning a website that a friend and I started about a year ago. It is a daily surf report so when choosing the best script/language to use for the new design, I found that a mixture of PHP and MySQL would be a good idea. I have currently set up OmniHTTPd and installed MySQL and PHP onto my homeserver. I want the site to be set up as follows: 1- I add the report, date and pictures (and amount of pictures...
3
2023
by: Jim S. | last post by:
Hi guys, i have lots of data for products (with different categories) and pictures that i would need it entered into a database on the website. How would i go about doing so? i was thinking about an excel sheet with each category as a sheet but i have no idea what to do about the pictures that will go with each product, (since i would not want the pictures in the mysql database.) any ideas?
8
11141
by: Ray in HK | last post by:
Will it be possible to specify the date format of type DATE during data loading ?
12
20936
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database contains the paths to the pictures. The database consists of two tables: TABLE DATA ID Name LastName
3
2754
by: nsh | last post by:
mailing.database.mysql, comp.lang.php subject: does "LOAD DATA" EVER work?!? I've tried EVERYTHING! version info: my isp is running my web page on a linux box with php ver. 4.4.1 according to phpinfo, the "mysql api client is ver. 4.0.25" - I have no idea how this relates, if at all, to the mysql engine's version. background:
9
3667
by: C.Joseph Drayton | last post by:
Hi All, I have a web site I am developing, and have a question. I would like members to be able to upload pictures. Do you think they should be saved as individual files or should they be put in an MySQL database? Which would you recommend, and do you have any sample code for accomplishing this? Ciao . . . C.Joseph
3
8653
by: Anthony Smith | last post by:
Can someone point me to a resource or something were I can set this up cleanly. I don't want to re-invest the wheel. I just want the most common way to do this. I know there is a database option and a non- database option. I prefer the none-database option. I will have 2 web servers with PHP installed.
15
6002
Markus
by: Markus | last post by:
What i want to do: Get urls from the database and echo them out into a multiple columned table i.e. 4 pictures per row (recently uploaded table) MY problem is: I have, in my MySQL database, the urls to the pictures that have been uploaded. I'm not really sure how i would get the urls to go into multiple rows... i can do it as a single row by writing this $db = "mahcuz";
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.