shlomikalfa Posted November 2, 2008 Share Posted November 2, 2008 Check this link: http://www.e-lephant.org/UserPictures/ShlomiKalfaPic.JPG A. How come i can't see it in my FTP account file structure ?! B. this is the page the created this file: //Collect variables. $UserID = "ShlomiKalfa"; $Picture = '0xFFD8FFE000104A46494600010101006000600000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D1832211C213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232FFC00011080009000703012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00E2E8A28AF993F713FFD9'; $SiteFileName = '/'.$UserID."Pic.JPG"; $cDir = str_ireplace("Server", "UserPictures", getcwd()); $filename = $cDir.$SiteFileName; echo $filename; //Save the file on host. $handle = fopen($filename, 'wb'); if (!$handle) {die("#1 Error: Cannot open file ($filename)");} // Write $somecontent to our opened file. if (fwrite($handle, $Picture) === FALSE) { echo "#2 Error: Cannot write to file ($filename)"; exit; } fclose($handle); // Make sure the new file exists! if (file_exists($filename)) { echo "The file $filename exists"; } else { echo "#3 Error: The file wasn't created! ($filename)"; exit; } What am i doing wrong ?! Quote Link to comment https://forums.phpfreaks.com/topic/131121-solved-weird-php-behavior/ Share on other sites More sharing options...
corbin Posted November 2, 2008 Share Posted November 2, 2008 $Picture = 'blah blah blah should be $Picture = blah blah blah Binary represented by hex is assigned like: $b = 0x1; Quote Link to comment https://forums.phpfreaks.com/topic/131121-solved-weird-php-behavior/#findComment-680777 Share on other sites More sharing options...
shlomikalfa Posted November 2, 2008 Author Share Posted November 2, 2008 oky.... even so... why isn't the file seen on my ftp client ?! and why the hell doesn't it contain the data i want it to ?! i used the binary mode 'wb' which should allow me to create binary files..... and yet it doesn't ...... Quote Link to comment https://forums.phpfreaks.com/topic/131121-solved-weird-php-behavior/#findComment-680789 Share on other sites More sharing options...
corbin Posted November 2, 2008 Share Posted November 2, 2008 Ahhh, just realized that hex data is stored numerically, so that will overflow the float limit. Hrmmm, I'mma go try to write something. Quote Link to comment https://forums.phpfreaks.com/topic/131121-solved-weird-php-behavior/#findComment-680813 Share on other sites More sharing options...
shlomikalfa Posted November 3, 2008 Author Share Posted November 3, 2008 oky, now that we've understood that thing... binary/hex is saved as a number and not as a string.... can we go further a head with my issue ?! A, (can't see my files through ftp client) is solved, it is due to the fact my list files is updating only after a while.... how about why can't i see the picture ?!!?! Quote Link to comment https://forums.phpfreaks.com/topic/131121-solved-weird-php-behavior/#findComment-681030 Share on other sites More sharing options...
Adam Posted November 3, 2008 Share Posted November 3, 2008 not too sure but try: $Picture = "\x0C0xFFD8FFE000104A46494600010101006000600000FFDB004300080606070605080707070909080A0C140D0C0B0B0C1912130F141D1A1F1E1D1A1C1C20242E2720222C231C1C2837292C30313434341F27393D38323C2E333432FFDB0043010909090C0B0C180D0D1832211C213232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232FFC00011080009000703012200021101031101FFC4001F0000010501010101010100000000000000000102030405060708090A0BFFC400B5100002010303020403050504040000017D01020300041105122131410613516107227114328191A1082342B1C11552D1F02433627282090A161718191A25262728292A3435363738393A434445464748494A535455565758595A636465666768696A737475767778797A838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE1E2E3E4E5E6E7E8E9EAF1F2F3F4F5F6F7F8F9FAFFC4001F0100030101010101010101010000000000000102030405060708090A0BFFC400B51100020102040403040705040400010277000102031104052131061241510761711322328108144291A1B1C109233352F0156272D10A162434E125F11718191A262728292A35363738393A434445464748494A535455565758595A636465666768696A737475767778797A82838485868788898A92939495969798999AA2A3A4A5A6A7A8A9AAB2B3B4B5B6B7B8B9BAC2C3C4C5C6C7C8C9CAD2D3D4D5D6D7D8D9DAE2E3E4E5E6E7E8E9EAF2F3F4F5F6F7F8F9FAFFDA000C03010002110311003F00E2E8A28AF993F713FFD9"; Apparently "\x0C" is a special control sequence in PHP, like "\n" or "\r" that is specially for hexadecimal ASCII values.. ??? worth a bash Adam Quote Link to comment https://forums.phpfreaks.com/topic/131121-solved-weird-php-behavior/#findComment-681036 Share on other sites More sharing options...
shlomikalfa Posted November 3, 2008 Author Share Posted November 3, 2008 well.. i tried to escape it as you suggested.... it doesn't work: 1. Tried to do it as you said... failed. 2. Tried to escape every byte solo:"\0xFF\0xD8\0xFF\0xE0\0x00\0x10\0x4A\0x46\0x49\0x46\0x00\0x01\0x01\0x01\0x00\0x60\0x00\0x60\0x00\...." Failed. 3. Tried to escape without "0x": "\FF\D8\FF\E0\00\10\4A\46\49\46\00\01\01\01\00\60\00\60\00\00\FF\E1\00\16\45\78\69\66\00\00\4...." Failed. Well... As a string [inside ""] the file is opened and the content is written as is... it seems like it doesn't parse the ASCII binary data in the file, thus when opening the file with a text viewer afterward the "content" is written inside as is.... [WHILE NOT ESCAPING] and while escaping it, it just doesn't parse everything... as if it works only with some chars..... Any Idea ?!? Perhaps anyone can tell me how can i set the string into a binary data ?! Quote Link to comment https://forums.phpfreaks.com/topic/131121-solved-weird-php-behavior/#findComment-681053 Share on other sites More sharing options...
kenrbnsn Posted November 3, 2008 Share Posted November 3, 2008 Please explain what you're trying to do with that string of HEX numbers. Ken Quote Link to comment https://forums.phpfreaks.com/topic/131121-solved-weird-php-behavior/#findComment-681108 Share on other sites More sharing options...
shlomikalfa Posted November 3, 2008 Author Share Posted November 3, 2008 that string of hex file is the content of a .jpg file in binary format. i want to upload content to a php page through a program protocol which sends the file's binary data in a post method to the server... so i am trying to stimulate it as if the data has already been received and save it. Oky, meanwhile i've managed to solve it. EDIT:: for others to come: To change binary back into string use this function [non unicode support though] function bin2asc($binaryInput, $byteLength=2) { if (strlen($binaryInput) % $byteLength) { echo 'Impropper Format'; return false; } // why run strlen() so many times in a loop? Use of constants = speed increase. $strSize = strlen($binaryInput); $origStr = ''; // jump between bytes. for($x=0; $x<$strSize; $x += $byteLength) { // extract character's binary code $charBinary = substr($binaryInput, $x, $byteLength); $origStr.= chr(hexdec($charBinary)); // conversion to ASCII. } return substr($origStr, 1); } Quote Link to comment https://forums.phpfreaks.com/topic/131121-solved-weird-php-behavior/#findComment-681110 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.