Re: [PHP] Using PHP to remove certain number of bytes from file



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?
.



Relevant Pages

  • Re: include function in stylesheet
    ... What are you trying to accomplish? ... I was trying to reduce the size of the file by removing some code from e.g. style.css and place the code in an other file e.g. nav.css. ... css Is a styling thingy and not a code like C++, Java, PHP, etc. ... That's why I can't use a php include function. ...
    (alt.html)
  • Re: [PHP] Dates and different time zones
    ... Okay, so I should set the default time zone to central GMT time, and then ... If you store the GMT offsets for each user at a certain time in the year, they will turn invalid when they switch from daylight savings to no savings. ... In PHP dates are stored as seconds from an arbitrary zero set at Jan 1st, 1970, so does MySql with date/time values though it shows them formatted but you can use the UNIX_TIMESTAMP function to get the actual timestamp. ... and then offset the values for localised display only. ...
    (php.general)
  • Re: include function in stylesheet
    ... Edwin van der Vaart wrote: ... What are you trying to accomplish? ... I was trying to reduce the size of the file by removing some code from e.g. style.css and place the code in an other file e.g. nav.css. ... That's why I can't use a php include function. ...
    (alt.html)
  • Re: [PHP] Dates and different time zones
    ... Dates and different time zones ... This has been giving us great fun since the winter dates and times need a different offset to the summer ones. ... It is no use to display dates and times stored in the database that are reliant on the daylight saving offset. ... PHP General Mailing List ...
    (php.general)
  • Re: include function in stylesheet
    ... What are you trying to accomplish? ... I was trying to reduce the size of the file by removing some code from e.g. style.css and place the code in an other file e.g. nav.css. ... That's why I can't use a php include function. ... Explicitly no permission given to Forum4Designers, onlinemarketingtoday, ...
    (alt.html)