On Sun, December 30, 2007 11:20 am, Scott Wilcox wrote:
> Is it possible with PHP to remove a certain number of bytes from a
> file,
> purely within PHP?
>
> If so, does someone have an example of doing this, removing the first
> 230 bytes from a file.
Something like this might work:
<?php
$path = "/full/path/to/file";
$file = fopen($path, 'r+') or die("Could not open $path");
//read 200 bytes
$goners = fread($file, 200);
if (!strlen($goners) === 200){
ftruncate($file, 0);
}
$offset = 0;
while(!feof($file)){
$buffer = fread($file, 2048);
ftell($file, $offset);
fwrite($file, $buffer);
$offset += strlen($buffer);
ftell($file, $offset + 200);
}
?>
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php