Forum Moderators: coopster

Message Too Old, No Replies

storing image into BLOB

         

need_help

1:07 am on Oct 20, 2004 (gmt 0)

10+ Year Member



Dear all,

I am having one problem which is that
- I can upload and store image into BLOB field normally on one machine-winXP where installed Apache 2 and php 4.x

- exactly same php code not functioning on the another machine-winXP where running Apache 1.3 and php 4.x

What is problem, can I have help from some one?

When I check the data stored in BLOB field (by means of saving into Desktop using MySQL Control Center) it were always stored 77 bytes of image/jpeg data, and 66 bytes of image/bmp files!

mipapage

9:24 pm on Oct 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the data transfer actually working for either of these?

For starters, when you post the file if you
print_r($_FILES);
does it return data in the array?

Lets say you have testimage.php with:
print_r($_FILES);

and a form (don't mind the html):

<form action="testimage.php" enctype="multipart/form-data" method="post"> 
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
<dl>
<dt><label for="userfile">Company Image</label></dt>
<dd><input type="file" id="userfile" name="userfile" /></dd>
</dl>
<input type="submit" value="Upload Image" />
</fieldset>
</form>

does it all work?



Oh, and Welcome to WebmasterWorld! [webmasterworld.com]

need_help

12:52 am on Oct 21, 2004 (gmt 0)

10+ Year Member



Thanks.

Exactly I did not checked by print_r($_FILES), but when I try to move uploaded file by function move_uploaded_file() it is works okey!

I checked the data readed as $data = addslashes(fread(fopen(...filename..,... filesize...) through echo $data; and in this case I am getting 111 bytes (real 77 bytes with slashes became 111).

coopster

10:48 am on Oct 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So the file does upload to the second machine? But when you try to store it in MySQL, that's when it fails? Have you made sure that you can connect to the second machine's MySQL server OK, etc?

need_help

12:15 am on Oct 22, 2004 (gmt 0)

10+ Year Member



Thanks for all.

So, I found out my mistake.
In case of Windows system the flag for function fopen() should be "rb":

i.e.: fopen(_filename_,"rb");

I had tried to read file using "r" flag. Now it is okey.

But I am still stupid, why in one winXP machine it works flag "r" but in another not?

coopster

12:53 am on Oct 22, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Based on the following quote from the fopen() [php.net] function page, one might assume it is your versions of Apache:


The default translation mode depends on the SAPI and version of PHP that you are using, so you are encouraged to always specify the appropriate flag for portability reasons.