On Mon, 2004-02-09 at 07:21, Anna Yamaguchi wrote:
> I would like to read first 224 bytes from a file A1, write them to another
> file, and then coming back to file A1 read bytes from 225 to the end of
> file.
> Could somebody help me with this? Please.

This is the traditional method:
// Open input file
$fh = fopen('some_file', 'rb');
// Read header
$header_data = fread($fh, 224);
// Open header output file
$ofh = fopen('some_other_file', 'wb');
// Write header
fwrite($ofh, $header_data);
// Get rest of file
do {
   $data = fread($fh, 8192);
   if (strlen($data) == 0) {
       break;
   }
   $contents .= $data;
} while (true);
fclose($fh);

If you know you want the entire file, you can always use
file_get_contents.  It may behoove you to check the file size first
before reading it entirely into memory:
if (filesize('some_file') <= 1048576) {
    $data = file_get_contents('some_file');
    $header_data = substr($data, 0, 224);
    $data = substr($data, 223);
}

-- 
Adam Bregenzer
[EMAIL PROTECTED]
http://adam.bregenzer.net/

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

Reply via email to