Re: [PHP] RE: RE: Sending MIME emails with base64 encoded attachments

2002-02-06 Thread Analysis and Solutions

Hey Petr:

> 2) I realize that in string obtained by fread() the following characters are
> changed:
> #0 () -> #92#48 (\0)
> #34 (") -> #92#34 (\")
> #39 (') -> #92#39 (\')
> #92 (\) -> #92#92 (\\)

WAIT A SECOND!  You've got the magic_quotes_runtime configuration variable
turned on!  To solve your problem you can:

a) turn off that feature via the the php.ini or .htaccess file
   http://www.php.net/manual/en/configuration.php#ini.magic-quotes-runtime

OR

b) use stripslashes() on the string you get back from the file
   http://www.php.net/manual/en/function.stripslashes.php 

Enjoy,

--Dan

-- 
PHP scripts that make your job easier
  http://www.analysisandsolutions.com/code/
 SQL Solution  |  Layout Solution  |  Form Solution
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Ave, Brooklyn NY 11232v: 718-854-0335f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] RE: RE: Sending MIME emails with base64 encoded attachments

2002-02-06 Thread Svarc, Petr
Title: RE: RE: Sending MIME emails with base64 encoded attachments





FINAL SOLUTION!


Hello


Ok. It's me, the last time :-)


> Let say I have a small 4byte file with content "AB#0C" 
> (ascii: #65,#66,#0,#67)
> I load it (using binary save fread into $txt)
> When I try to get third character (#0), quess what I get:
> $x = ord(substr($txt,2,1))
> 
> $x IS NOT 0!
> $x IS 92, which mean backslash. Fourth char is 48, which 
> means "0" and the fifth #67.
> 
> So, PHP replaces any #0 with "\0" in every string internally.


OK. THIS is true just for string obtained by fread()
Strings created internally are OK.


So the solution is:
1) get the string from the file using $str=fread($file,filesize($filename));
2) I realize that in string obtained by fread() the following characters are changed:
    #0 () -> #92#48 (\0)
    #34 (") -> #92#34 (\")
    #39 (') -> #92#39 (\')
    #92 (\) -> #92#92 (\\)
3) So solution is before put text into base64_encode procedure, do the following:
    $str=str_replace(chr(92).chr(48),chr(0),$str);
    $str=str_replace(chr(92).chr(34),chr(34),$str);
    $str=str_replace(chr(92).chr(39),chr(39),$str);
    $str=str_replace(chr(92).chr(92),chr(92),$str);
4) Now you can encode it.


It works.


Futhermore, I was trying to store some string to file using fwrite() method.
fwrite() works fine for all characters except backslash, where you have to
send there double backslash.
So fwrite($file,chr(0)) writes really #0, 
but for writing #92 you have to call fwrite($file,chr(92).chr(92));
For writing #0 you can also call fwrite($file,chr(92).chr(48));
(   and similary for all four cases stated above in point 3)   )



So, a thing, that's all for now


Have a nice day...


Petr Svarc




This electronic message transmission contains information from TMP Worldwide
and is confidential or privileged.  The information is intended to be for the use of
the individual or entity named above. If you are not the intended recipient, 
be aware that any disclosure, copying, distribution, or use of the contents of this
information is prohibited. If you have received this electronic transmission in error,
please notify us by telephone immediately at +44 (0)20 7406 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php