78 if (is_writeable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename,
'r+b'))) {
82 $OldThisFileInfo = $getID3->analyze($this->filename);
83 if (empty($OldThisFileInfo[
'real'][
'chunks']) && !empty($OldThisFileInfo[
'real'][
'old_ra_header'])) {
84 $this->errors[] =
'Cannot write Real tags on old-style file format';
90 if (empty($OldThisFileInfo[
'real'][
'chunks'])) {
91 $this->errors[] =
'Cannot write Real tags because cannot find DATA chunk in file';
96 foreach ($OldThisFileInfo[
'real'][
'chunks'] as $chunknumber => $chunkarray) {
97 $oldChunkInfo[$chunkarray[
'name']] = $chunkarray;
99 if (!empty($oldChunkInfo[
'CONT'][
'length'])) {
100 $this->paddedlength = max($oldChunkInfo[
'CONT'][
'length'], $this->paddedlength);
104 $new_PROP_tag_data = $this->
GeneratePROPchunk($OldThisFileInfo[
'real'][
'chunks'], $new_CONT_tag_data);
105 $new__RMF_tag_data = $this->
GenerateRMFchunk($OldThisFileInfo[
'real'][
'chunks']);
107 if (isset($oldChunkInfo[
'.RMF'][
'length']) && ($oldChunkInfo[
'.RMF'][
'length'] == strlen($new__RMF_tag_data))) {
108 fseek($fp_source, $oldChunkInfo[
'.RMF'][
'offset'], SEEK_SET);
109 fwrite($fp_source, $new__RMF_tag_data);
111 $this->errors[] =
'new .RMF tag ('.strlen($new__RMF_tag_data).
' bytes) different length than old .RMF tag ('.$oldChunkInfo[
'.RMF'][
'length'].
' bytes)';
117 if (isset($oldChunkInfo[
'PROP'][
'length']) && ($oldChunkInfo[
'PROP'][
'length'] == strlen($new_PROP_tag_data))) {
118 fseek($fp_source, $oldChunkInfo[
'PROP'][
'offset'], SEEK_SET);
119 fwrite($fp_source, $new_PROP_tag_data);
121 $this->errors[] =
'new PROP tag ('.strlen($new_PROP_tag_data).
' bytes) different length than old PROP tag ('.$oldChunkInfo[
'PROP'][
'length'].
' bytes)';
127 if (isset($oldChunkInfo[
'CONT'][
'length']) && ($oldChunkInfo[
'CONT'][
'length'] == strlen($new_CONT_tag_data))) {
130 fseek($fp_source, $oldChunkInfo[
'CONT'][
'offset'], SEEK_SET);
131 fwrite($fp_source, $new_CONT_tag_data);
138 if (empty($oldChunkInfo[
'CONT'])) {
140 $BeforeOffset = $oldChunkInfo[
'DATA'][
'offset'];
141 $AfterOffset = $oldChunkInfo[
'DATA'][
'offset'];
144 $BeforeOffset = $oldChunkInfo[
'CONT'][
'offset'];
145 $AfterOffset = $oldChunkInfo[
'CONT'][
'offset'] + $oldChunkInfo[
'CONT'][
'length'];
148 if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename,
'wb'))) {
151 fwrite($fp_temp, fread($fp_source, $BeforeOffset));
152 fwrite($fp_temp, $new_CONT_tag_data);
153 fseek($fp_source, $AfterOffset, SEEK_SET);
154 while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
155 fwrite($fp_temp, $buffer, strlen($buffer));
159 if (copy($tempfilename, $this->filename)) {
160 unlink($tempfilename);
165 unlink($tempfilename);
166 $this->errors[] =
'FAILED: copy('.$tempfilename.
', '.$this->filename.
')';
169 $this->errors[] =
'Could not fopen("'.$tempfilename.
'", "wb")';
179 $this->errors[] =
'Could not fopen("'.$this->filename.
'", "r+b")';
191 $oldCONTexists =
false;
192 foreach ($chunks as $key => $chunk) {
193 $chunkNameKeys[$chunk[
'name']] = $key;
194 if ($chunk[
'name'] ==
'CONT') {
195 $oldCONTexists =
true;
198 $newHeadersCount = $chunks[$chunkNameKeys[
'.RMF']][
'headers_count'] + ($oldCONTexists ? 0 : 1);
200 $RMFchunk =
"\x00\x00";
204 $RMFchunk =
'.RMF'.Helper::BigEndian2String(strlen($RMFchunk) + 8, 4).$RMFchunk;
217 $old_CONT_length = 0;
218 $old_DATA_offset = 0;
219 $old_INDX_offset = 0;
220 foreach ($chunks as $key => $chunk) {
221 $chunkNameKeys[$chunk[
'name']] = $key;
222 if ($chunk[
'name'] ==
'CONT') {
223 $old_CONT_length = $chunk[
'length'];
224 } elseif ($chunk[
'name'] ==
'DATA') {
225 if (!$old_DATA_offset) {
226 $old_DATA_offset = $chunk[
'offset'];
228 } elseif ($chunk[
'name'] ==
'INDX') {
229 if (!$old_INDX_offset) {
230 $old_INDX_offset = $chunk[
'offset'];
234 $CONTdelta = strlen($new_CONT_tag_data) - $old_CONT_length;
236 $PROPchunk =
"\x00\x00";
249 $PROPchunk =
'PROP'.Helper::BigEndian2String(strlen($PROPchunk) + 8, 4).$PROPchunk;
260 foreach ($this->tag_data as $key => $value) {
262 $this->tag_data[$key] = substr($value, 0, 65535);
265 $CONTchunk =
"\x00\x00";
267 $CONTchunk .=
Helper::BigEndian2String((!empty($this->tag_data[
'title']) ? strlen($this->tag_data[
'title']) : 0), 2);
268 $CONTchunk .= (!empty($this->tag_data[
'title']) ? strlen($this->tag_data[
'title']) :
'');
270 $CONTchunk .=
Helper::BigEndian2String((!empty($this->tag_data[
'artist']) ? strlen($this->tag_data[
'artist']) : 0), 2);
271 $CONTchunk .= (!empty($this->tag_data[
'artist']) ? strlen($this->tag_data[
'artist']) :
'');
273 $CONTchunk .=
Helper::BigEndian2String((!empty($this->tag_data[
'copyright']) ? strlen($this->tag_data[
'copyright']) : 0), 2);
274 $CONTchunk .= (!empty($this->tag_data[
'copyright']) ? strlen($this->tag_data[
'copyright']) :
'');
276 $CONTchunk .=
Helper::BigEndian2String((!empty($this->tag_data[
'comment']) ? strlen($this->tag_data[
'comment']) : 0), 2);
277 $CONTchunk .= (!empty($this->tag_data[
'comment']) ? strlen($this->tag_data[
'comment']) :
'');
279 if ($this->paddedlength > (strlen($CONTchunk) + 8)) {
280 $CONTchunk .= str_repeat(
"\x00", $this->paddedlength - strlen($CONTchunk) - 8);
283 $CONTchunk =
'CONT'.Helper::BigEndian2String(strlen($CONTchunk) + 8, 4).$CONTchunk;
295 if (is_writeable($this->filename) && is_file($this->filename) && ($fp_source = fopen($this->filename,
'r+b'))) {
299 $OldThisFileInfo = $getID3->analyze($this->filename);
300 if (empty($OldThisFileInfo[
'real'][
'chunks']) && !empty($OldThisFileInfo[
'real'][
'old_ra_header'])) {
301 $this->errors[] =
'Cannot remove Real tags from old-style file format';
307 if (empty($OldThisFileInfo[
'real'][
'chunks'])) {
308 $this->errors[] =
'Cannot remove Real tags because cannot find DATA chunk in file';
313 foreach ($OldThisFileInfo[
'real'][
'chunks'] as $chunknumber => $chunkarray) {
314 $oldChunkInfo[$chunkarray[
'name']] = $chunkarray;
317 if (empty($oldChunkInfo[
'CONT'])) {
324 $BeforeOffset = $oldChunkInfo[
'CONT'][
'offset'];
325 $AfterOffset = $oldChunkInfo[
'CONT'][
'offset'] + $oldChunkInfo[
'CONT'][
'length'];
327 if (is_writable($tempfilename) && is_file($tempfilename) && ($fp_temp = fopen($tempfilename,
'wb'))) {
330 fwrite($fp_temp, fread($fp_source, $BeforeOffset));
331 fseek($fp_source, $AfterOffset, SEEK_SET);
332 while ($buffer = fread($fp_source, $this->fread_buffer_size)) {
333 fwrite($fp_temp, $buffer, strlen($buffer));
337 if (copy($tempfilename, $this->filename)) {
338 unlink($tempfilename);
343 unlink($tempfilename);
344 $this->errors[] =
'FAILED: copy('.$tempfilename.
', '.$this->filename.
')';
347 $this->errors[] =
'Could not fopen("'.$tempfilename.
'", "wb")';
354 $this->errors[] =
'Could not fopen("'.$this->filename.
'", "r+b")';
static BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false)
GetId3() by James Heinrich info@getid3.org //.
GeneratePROPchunk(&$chunks, &$new_CONT_tag_data)
GetId3() by James Heinrich info@getid3.org //.
Create styles array
The data for the language used.
GenerateRMFchunk(&$chunks)