Connecting Tech Pros Worldwide Forums | Help | Site Map

MySQL BLOB data corrupted on retrieval

Member
 
Join Date: Nov 2008
Location: Chennai, India
Posts: 100
#1: Dec 29 '08
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
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,747
#2: Dec 29 '08

re: MySQL BLOB data corrupted on retrieval


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.
Member
 
Join Date: Nov 2008
Location: Chennai, India
Posts: 100
#3: Dec 30 '08

re: MySQL BLOB data corrupted on retrieval


Quote:

Originally Posted by Atli View Post

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.

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
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,747
#4: Dec 30 '08

re: MySQL BLOB data corrupted on retrieval


Quote:

Originally Posted by phpmagesh View Post

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

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:
Expand|Select|Wrap|Line Numbers
  1. 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?
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,747
#5: Dec 30 '08

re: MySQL BLOB data corrupted on retrieval


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

Moderator
Member
 
Join Date: Nov 2008
Location: Chennai, India
Posts: 100
#6: Dec 31 '08

re: MySQL BLOB data corrupted on retrieval


Quote:

Originally Posted by Atli View Post

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:

Expand|Select|Wrap|Line Numbers
  1. 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?

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
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,747
#7: Dec 31 '08

re: MySQL BLOB data corrupted on retrieval


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.
Reply