Re: [PHP] Using PHP to remove certain number of bytes from file
- From: ceo@xxxxxxxxx ("Richard Lynch")
- Date: Sun, 30 Dec 2007 18:53:59 -0600 (CST)
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?
.
- References:
- [PHP] Comparison Problems with 5.2.5
- From: Magnus Anderson
- Re: [PHP] Comparison Problems with 5.2.5
- From: Silvio Porcellana
- Using PHP to remove certain number of bytes from file
- From: Scott Wilcox
- [PHP] Comparison Problems with 5.2.5
- Prev by Date: Re: [PHP] Comparison Problems with 5.2.5
- Next by Date: Re: [PHP] looping through a $_POST variable
- Previous by thread: Re: [PHP] Using PHP to remove certain number of bytes from file
- Next by thread: Re: [PHP] Comparison Problems with 5.2.5
- Index(es):
Relevant Pages
|