Re: Viewing images stored in a database
From: Plex (invalid_at_thisisfake.com)
Date: 08/22/04
- Next message: theouimets_at_hotmail.com: "fopen question."
- Previous message: CJ Llewellyn: "Re: P{HP and ASP on the same page"
- In reply to: Andy Hassall: "Re: Viewing images stored in a database"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 21 Aug 2004 15:26:18 -0700
On Sat, 21 Aug 2004 11:43:50 +0100, Andy Hassall <andy@andyh.co.uk>
wrote:
>On Sat, 21 Aug 2004 02:37:59 -0700, Plex <invalid@thisisfake.com> wrote:
>
>>Ok, I've written this script which is supposed to take an image
>>uploaded by a user and put it in to a database, then at a later date
>>be able to extract the image from the database and display the image
>>to the user.
>>
>>The problem is that whenever I try to display the image, all I get is
>>an error message that the image contains errors. Can anyone tell me
>>where or why these errors might be coming up? Here is my script (I'm
>>pretty sure it's all there):
>>
>>
>>if($id) {
>>
>> $query = "select mimetype, data from files where id = $id";
>> $result = mysql_query($query);
>>
>> $data = mysql_result($result,0,"data");
>> $type = mysql_result($result,0,"mimetype");
>>
>> Header( "Content-type: $type");
>>
>> $size = 150; // new image width
>> $src = imagecreatefromstring($data);
>>
>[snip]
>
>>function prepareFile($blob) {
>> $blob = addslashes(fread(fopen($blob, "rb"),
>>filesize($blob)));
>> $blob = base64_encode($blob);
>
> As far as I can see, if you remove this line then the rest looks OK. For some
>reason you're trying to use base64 encoded data as if it were the original raw
>data; if you're uploading into a BLOB field you don't need this step.
>
>> return $blob;
>>}
I took out that line (I think it's a remnant from when I was trying
something else to get it to work), and uploaded another picture. This
time I also put in a couple lines to output the data receive from the
database into a file, so I could check if the data was somehow getting
corrupted.
Taking out that encode line, the file output worked (images uploaded
with it didn't). However, even thought the file output worked, I am
still getting the error message about the file containing errors, so I
think the problem may be somewhere in processing and outputting the
data, but I don't know enough about the image functions to know where
the problem might be (or if they're even the problem).
--Plex
- Next message: theouimets_at_hotmail.com: "fopen question."
- Previous message: CJ Llewellyn: "Re: P{HP and ASP on the same page"
- In reply to: Andy Hassall: "Re: Viewing images stored in a database"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|