Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/08/2023 in all areas

  1. It's better in that you're not doing a line-based approach any more. What I would say is you're getting a little too specific right now. If you look at the linked reference, you'll see: What you can take from that, is your file will essentially a repeating sequence of "\xFF\x??<marker>\x????<length>\x??...<data>". The two exceptions to worry about right away are the start of image and end of image markers, they don't have a length and data component. As such, you should start by being able to parse that repeating sequence. Don't worry about parsing what exactly is contained inside the data, just get the individual blocks. In pseudo code that'd be something like: while (!feof($file)){ $marker = findNextMarker($file); //Scan the file until you find a 0xFF?? value, return the ??. if ($marker !== 0xD8 && $marker !== 0xD9){ $length = parseLength($file); //Read two bytes, convert them to a integer length value $data = fread($file, $length - 2); // -2 because the encoded length includes the two bytes read above. } } I did this, and have a simple script that does like I said above, just parses out the different blocks and shows a hex dump of their data. I'll share eventually, but I want to see what you come up with after taking the above into consideration first.
    1 point
  2. So, Kicken, is this code better to your eyes (but the dang HH is still showing): <?php $SID_fileLines = ''; $SID_openFile = fopen('photo1200-96pc.jpg', 'rb'); //DSC_0001 $SID_bytes = ''; $position = 0; $SOI = 0; $signature = []; $dataBytes = 0; $trailer = ''; while (!feof($SID_openFile)/*.*/) { $SID_char1 = fgetc($SID_openFile); $SID_char2 = fgetc($SID_openFile); $SID_marker = $SID_char1 . $SID_char2; if (empty($SOI) && "\xFF\xD8" === $SID_marker) { $SOI = 1; continue; } if ("\xFF\xE0" === $SID_marker) { array_push($signature, utf8_encode($SID_char1)/*.*/); array_push($signature, utf8_encode($SID_char2)/*.*/); while ($dataBytes < 16) { $SID_header = fgetc($SID_openFile); if (ctype_cntrl($SID_header)) { $dataBytes += 1; continue; } array_push($signature, utf8_encode($SID_header)); $dataBytes += 1; } } if ("\xFF\xDB" === $SID_marker) { $trailer .= utf8_encode($SID_char1) . utf8_encode($SID_char2); break; //just a test to see how i could use fgetc } } fclose($SID_openFile); if (!empty($signature)) { foreach ($signature as $char) { $SID_bytes .= $char; } } if (!empty($SID_bytes)) { echo 'header: ' . $SID_bytes . ' : length = ' . strlen($SID_bytes) . '<br><br>'; } if (!empty($trailer)) { echo 'trailer: ' . $trailer . '<br><br>'; } ?> the only thing that i can think of at this time is to store two characters plus a marker for checking. I've never read a file before the last line code project. I think that it rolls smoother than the last one but it is a bit more complex. i really need to slep soon. My eyes are burning. Goodnight and Thanks for the tips, John
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.