|
Step 7: File Uploads and Virtual File Storage
MIME_Magic, VFS, and MP3_Id (PEAR) usage:
<?php
/** * Adds a file to Mopple's VFS backend. * * @param int $id The MP3 ID. * @param array $file A hash with the file information. * * @return mixed A hash with MP3ID1 tag information or a PEAR_Error on * failure. */ function &addFile($id, $file) { global $conf;
/* Check if this is really a MP3 file. */ require_once 'Horde/MIME/Magic.php'; if (MIME_Magic::analyzeFile($file['tmp_name']) != 'audio/mpeg') { return PEAR::raiseError(_("This file is no MP3 audio file.")); }
/* Instantiate VFS object. */ $vfs_params = Horde::getVFSConfig('mp3_vfs'); if (is_a($vfs_params, 'PEAR_Error')) { return $vfs_params; } require_once 'VFS.php'; $vfs = &VFS::singleton($vfs_params['type'], $vfs_params['params']);
/* Store file. */ $result = $vfs->write(MOPPLE_VFS, $id, $file['tmp_name'], true); if (is_a($result, 'PEAR_Error')) { return $result; }
/* Read MP3 ID. */ require_once 'MP3/Id.php'; $mp3id = &new MP3_Id(true); $result = $mp3id->read($file['tmp_name']); if (is_a($result, 'PEAR_Error')) { return $result; }
$tags = array(); foreach (array('name', 'artists', 'album', 'year', 'comment', 'track', 'genre', 'genreno', 'mpeg_ver', 'layer', 'bitrate', 'frequency', 'mode', 'copyright', 'length') as $tag) { $tags[$tag] = $mp3id->getTag($tag, null); }
return $tags; }
?>
|