30                 if (is_writeable($this->filename)) {
 
   31                         if ($fp_source = @fopen($this->filename, 
'r+b')) {
 
   35                                 $OldThisFileInfo = $getID3->
analyze($this->filename);
 
   36                                 if (empty($OldThisFileInfo[
'real'][
'chunks']) && !empty($OldThisFileInfo[
'real'][
'old_ra_header'])) {
 
   37                                         $this->errors[] = 
'Cannot write Real tags on old-style file format';
 
   42                                 if (empty($OldThisFileInfo[
'real'][
'chunks'])) {
 
   43                                         $this->errors[] = 
'Cannot write Real tags because cannot find DATA chunk in file';
 
   47                                 foreach ($OldThisFileInfo[
'real'][
'chunks'] as $chunknumber => $chunkarray) {
 
   48                                         $oldChunkInfo[$chunkarray[
'name']] = $chunkarray;
 
   50                                 if (!empty($oldChunkInfo[
'CONT'][
'length'])) {
 
   51                                         $this->paddedlength = max($oldChunkInfo[
'CONT'][
'length'], $this->paddedlength);
 
   55                                 $new_PROP_tag_data = $this->
GeneratePROPchunk($OldThisFileInfo[
'real'][
'chunks'], $new_CONT_tag_data);
 
   56                                 $new__RMF_tag_data = $this->
GenerateRMFchunk($OldThisFileInfo[
'real'][
'chunks']);
 
   58                                 if (@$oldChunkInfo[
'.RMF'][
'length'] == strlen($new__RMF_tag_data)) {
 
   59                                         fseek($fp_source, $oldChunkInfo[
'.RMF'][
'offset'], SEEK_SET);
 
   60                                         fwrite($fp_source, $new__RMF_tag_data);
 
   62                                         $this->errors[] = 
'new .RMF tag ('.strlen($new__RMF_tag_data).
' bytes) different length than old .RMF tag ('.$oldChunkInfo[
'.RMF'][
'length'].
' bytes)';
 
   67                                 if (@$oldChunkInfo[
'PROP'][
'length'] == strlen($new_PROP_tag_data)) {
 
   68                                         fseek($fp_source, $oldChunkInfo[
'PROP'][
'offset'], SEEK_SET);
 
   69                                         fwrite($fp_source, $new_PROP_tag_data);
 
   71                                         $this->errors[] = 
'new PROP tag ('.strlen($new_PROP_tag_data).
' bytes) different length than old PROP tag ('.$oldChunkInfo[
'PROP'][
'length'].
' bytes)';
 
   76                                 if (@$oldChunkInfo[
'CONT'][
'length'] == strlen($new_CONT_tag_data)) {
 
   79                                         fseek($fp_source, $oldChunkInfo[
'CONT'][
'offset'], SEEK_SET);
 
   80                                         fwrite($fp_source, $new_CONT_tag_data);
 
   86                                         if (empty($oldChunkInfo[
'CONT'])) {
 
   88                                                 $BeforeOffset = $oldChunkInfo[
'DATA'][
'offset'];
 
   89                                                 $AfterOffset  = $oldChunkInfo[
'DATA'][
'offset'];
 
   92                                                 $BeforeOffset = $oldChunkInfo[
'CONT'][
'offset'];
 
   93                                                 $AfterOffset  = $oldChunkInfo[
'CONT'][
'offset'] + $oldChunkInfo[
'CONT'][
'length'];
 
   95                                         if ($tempfilename = tempnam(
'*', 
'getID3')) {
 
   97                                                 if ($fp_temp = fopen($tempfilename, 
'wb')) {
 
  100                                                         fwrite($fp_temp, fread($fp_source, $BeforeOffset));
 
  101                                                         fwrite($fp_temp, $new_CONT_tag_data);
 
  102                                                         fseek($fp_source, $AfterOffset, SEEK_SET);
 
  104                                                                 fwrite($fp_temp, $buffer, strlen($buffer));
 
  108                                                         if (copy($tempfilename, $this->filename)) {
 
  109                                                                 unlink($tempfilename);
 
  113                                                         unlink($tempfilename);
 
  114                                                         $this->errors[] = 
'FAILED: copy('.$tempfilename.
', '.$this->filename.
') - '.strip_tags(ob_get_contents());
 
  118                                                         $this->errors[] = 
'Could not open '.$tempfilename.
' mode "wb" - '.strip_tags(ob_get_contents());
 
  130                                 $this->errors[] = 
'Could not open '.$this->filename.
' mode "r+b"';
 
  134                 $this->errors[] = 
'File is not writeable: '.$this->filename;
 
  139                 $oldCONTexists = 
false;
 
  140                 foreach ($chunks as $key => $chunk) {
 
  141                         $chunkNameKeys[$chunk[
'name']] = $key;
 
  142                         if ($chunk[
'name'] == 
'CONT') {
 
  143                                 $oldCONTexists = 
true;
 
  146                 $newHeadersCount = $chunks[$chunkNameKeys[
'.RMF']][
'headers_count'] + ($oldCONTexists ? 0 : 1);
 
  148                 $RMFchunk  = 
"\x00\x00"; 
 
  152                 $RMFchunk  = 
'.RMF'.getid3_lib::BigEndian2String(strlen($RMFchunk) + 8, 4).$RMFchunk; 
 
  157                 $old_CONT_length = 0;
 
  158                 $old_DATA_offset = 0;
 
  159                 $old_INDX_offset = 0;
 
  160                 foreach ($chunks as $key => $chunk) {
 
  161                         $chunkNameKeys[$chunk[
'name']] = $key;
 
  162                         if ($chunk[
'name'] == 
'CONT') {
 
  163                                 $old_CONT_length = $chunk[
'length'];
 
  164                         } elseif ($chunk[
'name'] == 
'DATA') {
 
  165                                 if (!$old_DATA_offset) {
 
  166                                         $old_DATA_offset = $chunk[
'offset'];
 
  168                         } elseif ($chunk[
'name'] == 
'INDX') {
 
  169                                 if (!$old_INDX_offset) {
 
  170                                         $old_INDX_offset = $chunk[
'offset'];
 
  174                 $CONTdelta = strlen($new_CONT_tag_data) - $old_CONT_length;
 
  176                 $PROPchunk  = 
"\x00\x00"; 
 
  189                 $PROPchunk  = 
'PROP'.getid3_lib::BigEndian2String(strlen($PROPchunk) + 8, 4).$PROPchunk; 
 
  194                 foreach ($this->tag_data as $key => $value) {
 
  196                         $this->tag_data[$key] = substr($value, 0, 65535);
 
  199                 $CONTchunk  = 
"\x00\x00"; 
 
  202                 $CONTchunk .= @$this->tag_data[
'title'];
 
  205                 $CONTchunk .= @$this->tag_data[
'artist'];
 
  208                 $CONTchunk .= @$this->tag_data[
'copyright'];
 
  211                 $CONTchunk .= @$this->tag_data[
'comment'];
 
  213                 if ($this->paddedlength > (strlen($CONTchunk) + 8)) {
 
  214                         $CONTchunk .= str_repeat(
"\x00", $this->paddedlength - strlen($CONTchunk) - 8);
 
  217                 $CONTchunk  = 
'CONT'.getid3_lib::BigEndian2String(strlen($CONTchunk) + 8, 4).$CONTchunk; 
 
  224                 if (is_writeable($this->filename)) {
 
  225                         if ($fp_source = @fopen($this->filename, 
'r+b')) {
 
  229                                 $OldThisFileInfo = $getID3->
analyze($this->filename);
 
  230                                 if (empty($OldThisFileInfo[
'real'][
'chunks']) && !empty($OldThisFileInfo[
'real'][
'old_ra_header'])) {
 
  231                                         $this->errors[] = 
'Cannot remove Real tags from old-style file format';
 
  236                                 if (empty($OldThisFileInfo[
'real'][
'chunks'])) {
 
  237                                         $this->errors[] = 
'Cannot remove Real tags because cannot find DATA chunk in file';
 
  241                                 foreach ($OldThisFileInfo[
'real'][
'chunks'] as $chunknumber => $chunkarray) {
 
  242                                         $oldChunkInfo[$chunkarray[
'name']] = $chunkarray;
 
  245                                 if (empty($oldChunkInfo[
'CONT'])) {
 
  251                                 $BeforeOffset = $oldChunkInfo[
'CONT'][
'offset'];
 
  252                                 $AfterOffset  = $oldChunkInfo[
'CONT'][
'offset'] + $oldChunkInfo[
'CONT'][
'length'];
 
  253                                 if ($tempfilename = tempnam(
'*', 
'getID3')) {
 
  255                                         if ($fp_temp = fopen($tempfilename, 
'wb')) {
 
  258                                                 fwrite($fp_temp, fread($fp_source, $BeforeOffset));
 
  259                                                 fseek($fp_source, $AfterOffset, SEEK_SET);
 
  261                                                         fwrite($fp_temp, $buffer, strlen($buffer));
 
  265                                                 if (copy($tempfilename, $this->filename)) {
 
  266                                                         unlink($tempfilename);
 
  270                                                 unlink($tempfilename);
 
  271                                                 $this->errors[] = 
'FAILED: copy('.$tempfilename.
', '.$this->filename.
') - '.strip_tags(ob_get_contents());
 
  275                                                 $this->errors[] = 
'Could not open '.$tempfilename.
' mode "wb" - '.strip_tags(ob_get_contents());
 
  285                                 $this->errors[] = 
'Could not open '.$this->filename.
' mode "r+b"';
 
  289                 $this->errors[] = 
'File is not writeable: '.$this->filename;