MySQL BLOB data corrupted on retrieval – PHP

  php

Q(Question):

Hi

I have tried this sample code in my database for file update, but some error occurred.

everything is going fine. uploaded the file successfully but, when i download the file which i uploaded in Database, the file is corrupted or flouted.

If the uploaded file is image, then the image is not displaying when it is downloaded,

So totally there is some minor problem with this code, can any one test and help me please. i just tried this in my local server, i got this output.

Regards
magesh N

Moderator note: This has been moved from the Uploading files into a MySQL database using PHP article. — Atli

A(Answer):

Hi magesh.

I just tested the code again on my test server (PHP5, MySQL5, Apache2.2).
Still works fine.

How is your server set up? Which versions of PHP and MySQL do you use?
Note that none of my examples specify a character set, so if your database uses something other than the default ISO character set, that *might* be causing problems.

Also make sure that you replace all database values and that nothing is being printed in the get_file script other than the file itself.

A(Answer):

@Atli

Hi,

Actually i m using Wamp server in my system, php5, Mysql5.0.51 and apache2.2.8.. for me too everything is working fine but the uploaded file is corrupted. i cant able to see what is inside after downloading that file again..

can you tell me what will be the problem in this,

Regards
magesh

A(Answer):

@phpmagesh

Not really without any more information.
This code should be working fine on a standard installation of the software you mentioned.

We would need to know how your server is different from the standard installation.
Do you use a language specific character set? Like Chinese or Japanese?
Does your browser default to a character set other than ISO? (Which browse do you use?)

Try issuing the following command on your MySQL database:

SHOW CREATE TABLE FileStorage\G

Post the entire CREATE TABLE command that gives you here. (within [code] tags please).
There I would be most interested in the CHARSET clause at the end. It should be "latin1". If it is not, that might be a problem.

The corrupted file, how exactly is it corrupted? How does the corruption present itself?
Can you download it, but it’s empty? If not, is there a difference in sizes compared to what MySQL says it should be?

A(Answer):

I have moved this discussion into it’s own thread, to avoid cluttering the article thread.

Moderator

A(Answer):

@Atli

Hi,

I tried the query which you gave to me, it displayed the follwoing error.

************************************************** ****
Error:

SQL query:

SHOW CREATE TABLE FileStorage \ G

MySQL said:
#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘\G’ at line 1
************************************************** ********************

What will be the problem in this please can you tell me,

Thanks in advance,

Regards
magesh

A(Answer):

Try removing the \G.

It is used by the MySQL CLI to sort the rows differently.
Probably won’t work if your using some other client, like phpMyAdmin.

LEAVE A COMMENT