有可以写/读 id3 标签的 lib getid3。这是我的上传脚本:
// 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;
请帮助:)