Linux — PHP Id3tag изменение загруженного файла

есть библиотека lib getid3, которая может писать / читать теги id3. Вот мой скрипт загрузки:

// Validate the files to be uploaded
if(empty($error)) {
$tpath = __DIR__ .'/../uploads/tracks/';
$mpath = __DIR__ .'/../uploads/media/';

if($type) {
if(isset($_FILES['track']['name'])) {
// Get the total uploaded size
$query = $this->db->query(sprintf("SELECT (SELECT SUM(`size`) FROM `tracks` WHERE `uid` = '%s') as upload_size", $this->db->real_escape_string($this->id)));
$result = $query->fetch_assoc();

$ext = pathinfo($_FILES['track']['name'][$num], PATHINFO_EXTENSION);
$size = $_FILES['track']['size'][$num];
$fullname = $_FILES['track']['name'][$num];
$allowedExt = explode(',', $this->track_format);
$maxsize = $this->track_size;

// Validate the total upload size allowed
if(($result['upload_size'] + $size) > $this->track_size_total) {
$error[] = array(0, saniscape($values['title']));
}

// Get file type validation
$track = validateFile($_FILES['track']['tmp_name'][$num], $_FILES['track']['name'][$num], $allowedExt, 1);

if($track['valid'] && $size < $maxsize && $size > 0) {
$t_tmp_name = $_FILES['track']['tmp_name'][$num];
$name = pathinfo($_FILES['track']['name'][$num], PATHINFO_FILENAME);
$size = $_FILES['track']['size'][$num];
$tName = mt_rand().'_'.mt_rand().'_'.mt_rand().'.'.$this->db->real_escape_string($ext);// Send the track name in array format to the function
$values['name'] = $tName;
$values['size'] = $size;

$t_upload = true;
} elseif($_FILES['track']['name'][$num] == '') {
// If the file size is higher than allowed or 0
$error[] = array(1);
}
if(!empty($ext) && ($size > $maxsize || $size == 0)) {
// If the file size is higher than allowed or 0
$error[] = array(2, saniscape($values['title']), fsize($maxsize));
}
if(!empty($ext) && !$track['valid']) {
// If the file format is not allowed
$error[] = array(3, saniscape($values['title']), implode(', ', $allowedExt));
}
}
}

if(empty($GLOBALS['multiart'])) {
if(isset($_FILES['art']['name'])) {
foreach($_FILES['art']['error'] as $key => $err) {
$ext = pathinfo($_FILES['art']['name'][$key], PATHINFO_EXTENSION);
$size = $_FILES['art']['size'][$key];
$allowedExt = explode(',', $this->art_format);
$maxsize = $this->art_size;

// Get file type validation
$image = validateFile($_FILES['art']['tmp_name'][$key], $_FILES['art']['name'][$key], $allowedExt, 0);

if($image['valid'] && $size < $maxsize && $size > 0 && !empty($image['width']) && !empty($image['height'])) {
$m_tmp_name = $_FILES['art']['tmp_name'][$key];
$name = pathinfo($_FILES['art']['name'][$key], PATHINFO_FILENAME);
$fullname = $_FILES['art']['name'][$key];
$size = $_FILES['art']['size'][$key];

// If there's no error during the track's upload
if(empty($error)) {
// Generate the file name & store it into a super global to check when multi upload
$mName = $GLOBALS['multiart'] = mt_rand().'_'.mt_rand().'_'.mt_rand().'.'.$this->db->real_escape_string($ext);
}

// Delete the old image when editing the track
if(!$type) {
$query = $this->db->query(sprintf("SELECT `art` FROM `tracks` WHERE `id` = '%s'", $this->db->real_escape_string($_GET['id'])));
$result = $query->fetch_assoc();
deleteImages(array($result['art']), 2);
}

// Send the image name in array format to the function
$values['art'] = $mName;

$m_upload = true;
} elseif($_FILES['art']['name'][$key] == '') {
// If no file is selected
if($type) {
$values['art'] = 'nocover6.jpg';
} else {
// If the cover artwork is not selected, unset the image so that it doesn't update the current one
unset($values['art']);
}
}
if(!empty($ext) && ($size > $maxsize || $size == 0)) {
// If the file size is higher than allowed or 0
$error[] = array(4, fsize($maxsize));
}
if(!empty($ext) && !$image['valid']) {
// If the file format is not allowed
$error[] = array(5, implode(', ', $allowedExt));
}
}
}
} else {
// Generate a new file name
$ext = pathinfo($GLOBALS['multiart'], PATHINFO_EXTENSION);
$finalName = mt_rand().'_'.mt_rand().'_'.mt_rand().'.'.$this->db->real_escape_string($ext);
// Copy the previous track image
copy($mpath.$GLOBALS['multiart'], $mpath.$finalName);
// Store the new file name
$values['art'] = $finalName;
}
}

if(!empty($error)) {
return array(0, $error);
} else {
if($t_upload) {
// Move the file into the uploaded folder
move_uploaded_file($t_tmp_name, $tpath.$tName);

}
if($m_upload) {
// Move the file into the uploaded folder
move_uploaded_file($m_tmp_name, $mpath.$mName);
}
return array(1, $values);
}

}

Я пытаюсь изменить теги id3 загруженного файла сразу после того, как он был загружен, и его имя хранится в $ tName. После того, как я поставил скрипт редактирования id3 после

} else {
if($t_upload) {
// Move the file into the uploaded folder
move_uploaded_file($t_tmp_name, $tpath.$tName);

Мой скрипт загрузки не работает, я не могу загрузить музыку или что-то еще. Где мне поставить скрипт записи id3? Вот скрипт id3write:

                $TextEncoding = 'UTF-8';
$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TextEncoding));
$tagwriter = new getid3_writetags;
$tagwriter->filename = $tpath.$tname;
$tagwriter->tagformats = array('id3v2.3');
$tagwriter->overwrite_tags = true;
$tagwriter->remove_other_tags = true;
$tagwriter->tag_encoding = $TextEncoding;
$TagData = array(
'album'         => array('Album'),
'comment'       => array('Text'),
'track'         => array('2ndtext'),);
$tagwriter->tag_data = $TagData;

Помогите пожалуйста 🙂

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]