image into mysql and out of mysql

image into mysql and out of mysql

am 21.10.2005 15:07:51 von feudalac

What i need is to store lost of small images into mysql database and
read them later and display them.

i know that it can be done, but don't know how it can be done...


thanks

Re: image into mysql and out of mysql

am 21.10.2005 17:33:03 von Jamie Davison

On 10/21/05 9:07 AM, in article djap76$nq1$1@ss405.t-com.hr, "Feudalac!"
wrote:

> What i need is to store lost of small images into mysql database and
> read them later and display them.
>
> i know that it can be done, but don't know how it can be done...
>
>
> thanks


See . .

http://www.phpbuilder.com/columns/florian19991014.php3

Re: image into mysql and out of mysql

am 22.10.2005 09:08:13 von Andreas Edin

It's pretty easy upload and download images or other files
to and from a MySql server.

Here is an example how to upload it:
require('connect/open_connect.php');

$form_description = $_POST['form_description'];
$form_type_upload = $_POST['type_upload'];
$data = addslashes(fread(fopen($_FILES['form_data']['tmp_name'],
"rb"), filesize($_FILES['form_data']['tmp_name'])));
$form_data_name = $_FILES['form_data']['name'];
$form_data_size = $_FILES['form_data']['size'];
$form_data_type = $_FILES['form_data']['type'];
}

$result=MYSQL_QUERY("INSERT INTO binary_data (categori,
description,bin_data,filename,filesize,filetype) ".
"VALUES
('$form_type_upload','$form_description','$data','$form_data _name','$for
m_data_size','$form_data_type')");

require('connect/close_connect.php');
?>

Here is an example how to download for viewing or download:

if($_GET['id']) {
require('connect/open_connect.php');

$query = "select description, bin_data, filename, filesize,
filetype from binary_data where id=".$_GET['id'];
$result = @MYSQL_QUERY($query);

$data = @MYSQL_RESULT($result,0,"bin_data");
$type = @MYSQL_RESULT($result,0,"filetype");
$size = @MYSQL_RESULT($result,0,"filesize");
$name = @MYSQL_RESULT($result,0,"filename");
$desc = @MYSQL_RESULT($result,0,"description");

require('connect/close_connect.php');

header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: $desc");
echo $data;

};
?>

Internet explorer will try to open det file/image, and if it can't
open it with a program it will send you a download prompt insteed.

Good Lucky! If you want more detailed description just say it.
Best regards Andreas Edin, Sweden

Re: image into mysql and out of mysql

am 24.10.2005 15:01:14 von feudalac

Andreas Edin wrote:

>
> It's pretty easy upload and download images or other files
> to and from a MySql server.
>
> Here is an example how to upload it:
> > require('connect/open_connect.php');
>
> $form_description = $_POST['form_description'];
> $form_type_upload = $_POST['type_upload'];
> $data = addslashes(fread(fopen($_FILES['form_data']['tmp_name'],
> "rb"), filesize($_FILES['form_data']['tmp_name'])));
> $form_data_name = $_FILES['form_data']['name'];
> $form_data_size = $_FILES['form_data']['size'];
> $form_data_type = $_FILES['form_data']['type'];
> }
>
> $result=MYSQL_QUERY("INSERT INTO binary_data (categori,
> description,bin_data,filename,filesize,filetype) ".
> "VALUES
> ('$form_type_upload','$form_description','$data','$form_data _name','$f
> or m_data_size','$form_data_type')");
>
> require('connect/close_connect.php');
> ?>
>
> Here is an example how to download for viewing or download:
> >
> if($_GET['id']) {
> require('connect/open_connect.php');
>
> $query = "select description, bin_data, filename, filesize,
> filetype from binary_data where id=".$_GET['id'];
> $result = @MYSQL_QUERY($query);
>
> $data = @MYSQL_RESULT($result,0,"bin_data");
> $type = @MYSQL_RESULT($result,0,"filetype");
> $size = @MYSQL_RESULT($result,0,"filesize");
> $name = @MYSQL_RESULT($result,0,"filename");
> $desc = @MYSQL_RESULT($result,0,"description");
>
> require('connect/close_connect.php');
>
> header("Content-type: $type");
> header("Content-length: $size");
> header("Content-Disposition: attachment; filename=$name");
> header("Content-Description: $desc");
> echo $data;
>
> };
> ?>
>
> Internet explorer will try to open det file/image, and if it can't
> open it with a program it will send you a download prompt insteed.
>
> Good Lucky! If you want more detailed description just say it.
> Best regards Andreas Edin, Sweden

but what if i don't want to download them? i want to show them in a
html page?

Re: image into mysql and out of mysql

am 24.10.2005 18:03:25 von Andreas Edin

Feudalac! wrote:

> Andreas Edin wrote:
>
> >
> > It's pretty easy upload and download images or other files
> > to and from a MySql server.
> >
> > Here is an example how to upload it:
> > > > require('connect/open_connect.php');
> >
> > $form_description = $_POST['form_description'];
> > $form_type_upload = $_POST['type_upload'];
> > $data = addslashes(fread(fopen($_FILES['form_data']['tmp_name'],
> > "rb"), filesize($_FILES['form_data']['tmp_name'])));
> > $form_data_name = $_FILES['form_data']['name'];
> > $form_data_size = $_FILES['form_data']['size'];
> > $form_data_type = $_FILES['form_data']['type'];
> > }
> >
> > $result=MYSQL_QUERY("INSERT INTO binary_data (categori,
> > description,bin_data,filename,filesize,filetype) ".
> > "VALUES
> > ('$form_type_upload','$form_description','$data','$form_data _name','
> > $f or m_data_size','$form_data_type')");
> >
> > require('connect/close_connect.php');
> > ?>
> >
> > Here is an example how to download for viewing or download:
> > > >
> > if($_GET['id']) {
> > require('connect/open_connect.php');
> >
> > $query = "select description, bin_data, filename, filesize,
> > filetype from binary_data where id=".$_GET['id'];
> > $result = @MYSQL_QUERY($query);
> >
> > $data = @MYSQL_RESULT($result,0,"bin_data");
> > $type = @MYSQL_RESULT($result,0,"filetype");
> > $size = @MYSQL_RESULT($result,0,"filesize");
> > $name = @MYSQL_RESULT($result,0,"filename");
> > $desc = @MYSQL_RESULT($result,0,"description");
> >
> > require('connect/close_connect.php');
> >
> > header("Content-type: $type");
> > header("Content-length: $size");
> > header("Content-Disposition: attachment; filename=$name");
> > header("Content-Description: $desc");
> > echo $data;
> >
> > };
> > ?>
> >
> > Internet explorer will try to open det file/image, and if it can't
> > open it with a program it will send you a download prompt insteed.
> >
> > Good Lucky! If you want more detailed description just say it.
> > Best regards Andreas Edin, Sweden
>
> but what if i don't want to download them? i want to show them in a
> html page?


It's exactly what this code does

> > header("Content-type: $type");
> > header("Content-length: $size");
> > header("Content-Disposition: attachment; filename=$name");
> > header("Content-Description: $desc");
> > echo $data;


Content-type:
Sends information to the browser what type of document it is.

Content-length:
Describes how many bytes the browser shall expect to get

Content-Disposition:
How it will be sent, as an attachment, and what name it shall get.

Content-Description:
A short description about the file

Now you have sent all the information your browser need. But you don't
really have to send "Content-Disposition" and "Content-Description" it
works well without them.

The next step is to send the file from the database. And that's easy
just "echo $data;" in this example.

But if the browser doesn't know how to open the file by it's
content-type, it will automaticly open a download prompt.

If you want more detailed description just say it.
Best regards Andreas Edin, Sweden

--

Re: image into mysql and out of mysql

am 24.10.2005 20:23:02 von unknown

Post removed (X-No-Archive: yes)

Re: image into mysql and out of mysql

am 25.10.2005 13:21:33 von feudalac

Andreas Edin wrote:

> Feudalac! wrote:
>
> > Andreas Edin wrote:
> >
> >
>
>
>
> Now you have sent all the information your browser need. But you don't
> really have to send "Content-Disposition" and "Content-Description" it
> works well without them.
>
> The next step is to send the file from the database. And that's easy
> just "echo $data;" in this example.
>
> But if the browser doesn't know how to open the file by it's
> content-type, it will automaticly open a download prompt.
>
> If you want more detailed description just say it.
> Best regards Andreas Edin, Sweden

but i must display some text and then the image, after that some more
text and another image...

the example above is very helpful but the main problem stil exists...

I have a catalog with very small images (filesize no more that 2k) and
want to store those images in a database. when the catalog is displayed
- every image must be next to the corresponding type of product...

Re: image into mysql and out of mysql

am 25.10.2005 13:22:49 von feudalac

rich@newsguy.com wrote:

> In article , Feudalac! says...
> >
> > Andreas Edin wrote:
> >
> >>
> >> It's pretty easy upload and download images or other files
> >> to and from a MySql server.
> >>
> >> Here is an example how to upload it:
> >> > >> require('connect/open_connect.php');
> >>
> >> $form_description = $_POST['form_description'];
> >> $form_type_upload = $_POST['type_upload'];
> >> $data =
> addslashes(fread(fopen($_FILES['form_data']['tmp_name'], >> "rb"),
> filesize($_FILES['form_data']['tmp_name']))); >> $form_data_name
> = $_FILES['form_data']['name']; >> $form_data_size =
> $_FILES['form_data']['size']; >> $form_data_type =
> $_FILES['form_data']['type']; >> }
> >>
> >> $result=MYSQL_QUERY("INSERT INTO binary_data (categori,
> >> description,bin_data,filename,filesize,filetype) ".
> >> "VALUES
> >>
> ('$form_type_upload','$form_description','$data','$form_data _name','$f
> >> or m_data_size','$form_data_type')"); >>
> >> require('connect/close_connect.php');
> >> ?>
> >>
> >> Here is an example how to download for viewing or download:
> >> > >>
> >> if($_GET['id']) {
> >> require('connect/open_connect.php');
> >>
> >> $query = "select description, bin_data, filename, filesize,
> >> filetype from binary_data where id=".$_GET['id'];
> >> $result = @MYSQL_QUERY($query);
> >>
> >> $data = @MYSQL_RESULT($result,0,"bin_data");
> >> $type = @MYSQL_RESULT($result,0,"filetype");
> >> $size = @MYSQL_RESULT($result,0,"filesize");
> >> $name = @MYSQL_RESULT($result,0,"filename");
> >> $desc = @MYSQL_RESULT($result,0,"description");
> >>
> >> require('connect/close_connect.php');
> >>
> >> header("Content-type: $type");
> >> header("Content-length: $size");
> >> header("Content-Disposition: attachment; filename=$name");
> >> header("Content-Description: $desc");
> >> echo $data;
> >>
> >> };
> >> ?>
> >>
> >> Internet explorer will try to open det file/image, and if it can't
> >> open it with a program it will send you a download prompt insteed.
> >>
> >> Good Lucky! If you want more detailed description just say it.
> >> Best regards Andreas Edin, Sweden
> >
> > but what if i don't want to download them? i want to show them in a
> > html page?
> >
>
> If you didn't want to store and retrieve the images through MySQL,
> you can store the path information instead. That way you only have to
> use and maintain a simple string of text.
>
> Since you want to display images in your HTML, they would usually be
> stored in your web space. You can use SQL to build some type of query
> (e.g. sort by date, name, etc) and dynamically print the results in
> your HTML using the file name and/or path information.
>
> Rich
> --
> Newsguy -- http://newsguy.com

that i allready have solved but i am limited to the number of files i
can have and allso have a problem uploading them thru the web interface
(no write rights on the desired folder...)

Re: image into mysql and out of mysql

am 25.10.2005 20:50:00 von Andreas Edin

Feudalac! wrote:

> Andreas Edin wrote:
>
> > Feudalac! wrote:
> >
> > > Andreas Edin wrote:
> > >
> > >
> >
> >
> >
> > Now you have sent all the information your browser need. But you
> > don't really have to send "Content-Disposition" and
> > "Content-Description" it works well without them.
> >
> > The next step is to send the file from the database. And that's easy
> > just "echo $data;" in this example.
> >
> > But if the browser doesn't know how to open the file by it's
> > content-type, it will automaticly open a download prompt.
> >
> > If you want more detailed description just say it.
> > Best regards Andreas Edin, Sweden
>
> but i must display some text and then the image, after that some more
> text and another image...
>
> the example above is very helpful but the main problem stil exists...
>
> I have a catalog with very small images (filesize no more that 2k) and
> want to store those images in a database. when the catalog is
> displayed - every image must be next to the corresponding type of
> product...

Just create two table's in your MySQL database. One with you images and
one with the meta information about the image. Decide witch one you are
going to use as primary listing. And for each itteration in the primary
table you do a sub query in the other table. And for each itteration
you create a new output to the webbrowser.


If you want more detailed description just say it.
Best regards Andreas Edin, Swede
--

Downloading image from MySQL

am 04.11.2005 17:52:42 von joanna.urban

:shock: I'm having the same type of problem. Though I was able to
upload the file into the database, I'm unable to get it display
properly on the site. It spits it out in binary. I've looked on a
bunch of different sites and they all seem to give the same sample
code, it just doesn't work for me.

I'm trying to display the image:
$data = $row['thumbnail'];
$type = ("image/jpg");
header( "Content-type: $type");
echo $data;

And it's just displaying a bunch of crap.
I know that the file did properly download.
I think the problem has something to do with the header.

If i put the header near the top of the page and not close to the echo
$data; then it trys to open the php file i'm working on. And if I put
it where is it, it says that: Warning: Cannot modify header
information - headers already sent

HELP! I'm going nutso over here.
:shock: :?: :!:


Sent via Archivaty.com

Re: Downloading image from MySQL

am 05.11.2005 23:51:22 von Hans-Peter Sauer

On Fri, 04 Nov 2005 10:52:42 -0600, jourb wrote:

> I'm trying to display the image:

Make sure the script outputs nothing before the headers.

header('Content-type: ' . $type);
header('Content-length: ' . strlen($data) . "\n\n");
die($data);

--

..