Re: Viewing images stored in a database

From: Plex (invalid_at_thisisfake.com)
Date: 08/22/04


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



Relevant Pages

  • Re: Viewing images stored in a database
    ... >uploaded by a user and put it in to a database, ... >The problem is that whenever I try to display the image, ... reason you're trying to use base64 encoded data as if it were the original raw ... if you're uploading into a BLOB field you don't need this step. ...
    (comp.lang.php)
  • Re: Visitor access to database
    ... A visitor uploading a file to a database on the server is simple? ... are you really storing these files in a database? ... us with more detailed information, we can help you to know what needs to be ...
    (microsoft.public.frontpage.programming)
  • Re: [PHP] Re: [BULK] Re: [PHP] OK to have many files in one folder?
    ... database information is stored in files. ... Request is sent to the server via a script. ... For a filesystem, it's simpler. ... Uploading: ...
    (php.general)
  • Re: Image Question
    ... the database though... ... and "uploading" it to the server. ... > guy was storing 20,000 video files? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: MDB made on one pc to be used on another.
    ... I also uploaded the file to my website and got them to download it from ... I imported the data and made an Access database here at home, ... I tried a work around by uploading the file to my website and getting ... 1.In Internet Explorer, click Tools, and then click Internet Options. ...
    (microsoft.public.access.conversion)