Jump to content


Photo

storing Word and PDFs as BLOBs


  • Please log in to reply
5 replies to this topic

#1 warnockm

warnockm
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 20 April 2006 - 07:09 PM

Hi, i'm having some trouble storing and recovering Word/.doc and PDF files as blobs. i'm loading the content from an uploaded file and storing it to a BLOB. i realized i needed addslashes() to make it store properly, however, stripslashes() on the download strips slashes that were in the original file, rendering it unopenable. Am i missing something?

Thanks,

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 21 April 2006 - 03:16 AM

That's seems impossible -- these functions are each other's inverse, such that x = stripslashes(addslashes(x)). There must be something else going on -- are you sure magic quotes aren't on?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 warnockm

warnockm
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 24 April 2006 - 01:01 PM

[!--quoteo(post=367087:date=Apr 20 2006, 11:16 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Apr 20 2006, 11:16 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
That's seems impossible -- these functions are each other's inverse, such that x = stripslashes(addslashes(x)). There must be something else going on -- are you sure magic quotes aren't on?
[/quote]

Thanks for the reply. I checked and magic quotes are OFF. When i uploaded a file and downloaded and compared the original to the downlaoded. There are slashes in the original that are being removed. Isn't it possible that there are slashes not added by addslashes() that are removed by strip slashes?

#4 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 24 April 2006 - 02:24 PM

Try not using [a href=\"http://www.php.net/stripslashes\" target=\"_blank\"]stripslashes[/a] when retrieving the information from the database.

When you use addslashes you're only escaping characters that would be misinterpreted by MYSQL had you not. The end result is that only your original data is stored, not the slashes that were used to escape the data. You should only need to worry about stripping slashes from the data retrieved if [a href=\"http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-runtime\" target=\"_blank\"]magic_quotes_runtime[/a] is on.

#5 warnockm

warnockm
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 24 April 2006 - 03:02 PM

[!--quoteo(post=367984:date=Apr 24 2006, 10:24 AM:name=shoz)--][div class=\'quotetop\']QUOTE(shoz @ Apr 24 2006, 10:24 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Try not using [a href=\"http://www.php.net/stripslashes\" target=\"_blank\"]stripslashes[/a] when retrieving the information from the database.

When you use addslashes you're only escaping characters that would be misinterpreted by MYSQL had you not. The end result is that only your original data is stored, not the slashes that were used to escape the data. You should only need to worry about stripping slashes from the data retrieved if [a href=\"http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-runtime\" target=\"_blank\"]magic_quotes_runtime[/a] is on.
[/quote]

yeah, that fixed it. But my question is, why? I don't have Magic quotes on in my php.ini

#6 shoz

shoz
  • Staff Alumni
  • Advanced Member
  • 600 posts

Posted 24 April 2006 - 03:25 PM

First let me point out that [a href=\"http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-runtime\" target=\"_blank\"]magic_quotes_runtime[/a] and [a href=\"http://www.php.net/manual/en/ref.info.php#ini.magic-quotes-gpc\" target=\"_blank\"]magic_quotes_gpc[/a] are different things.

As far as your question goes. The fact that magic_quotes_runtime is not on, is the reason why you don't need to stripslashes from the database retrieved data.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users