Download Album
Posted: Tue Mar 22, 2005 3:38 pm
Similar to the feature request to stream each song seperately it would be interesting to be able to download an entire album.
For example as a ZIP file.
For example as a ZIP file.
The zip library in PHP can only be used to extract zip files.xdreamer wrote:Similar to the feature request to stream each song seperately it would be interesting to be able to download an entire album.
For example as a ZIP file.
Nice work.lylos wrote:I believe I now have this function enabled, mind you my php is hacked all to hell and it looks awful, but I think it works... If you would like to know what I did please reply back and I'll add all steps. And if you would like to see a demo of this, check out my website, you can login with anonymous access.
edit: no more urls...
Code: Select all
// +---------------------------------------------------------------------------+
// | Download Album |
// +---------------------------------------------------------------------------+
function downloadalbum($album_id)
{
require("include/ss_zip.class.php");
global $cfg;
authenticate('access_download');
ini_set('max_execution_time', $cfg['download_timeout']);
$zip= new ss_zip('',1);
$test = mysql_query('SELECT relative_file FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '" ORDER BY relative_file');
while($file = mysql_fetch_array($test))
{
$filename = mysql_query('SELECT artist, title FROM track WHERE relative_file = "' . mysql_real_escape_string($file[0]) .'"');
$name = mysql_fetch_array($filename);
$file2 = $cfg['media_dir'] . $file[0];
$zip->add_file($file2,$file[0]);
};
$albumname = mysql_query('SELECT artist, album FROM album WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
$albumname2 = mysql_fetch_array($albumname);
$combined2 = $albumname2[0] ." - ". $albumname2[1] .".zip";
header('Content-Type: application/force-download');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' . $combined2 . '"');
$zip->save($combined2, b);
}
Code: Select all
if ($command == 'downloadalbum') downloadalbum($album_id);
Its Freeware you may use it as you wish but you may not redistribute it alone.
For commercial applications it is strongly recommended to upgrade to PRO version
Code: Select all
cookie('netjukebox_hash')
On netjukebox 3.75 the cookie('netjukebox_hash') cannot be used as session id.lylos wrote:In the login script is there a session ID that is created or some kind of key that we can use to create a directory to store the zip in? In my situation, I have everyone log in via the anonymous login to use my script. Storing the zip file in a directory based on username wouldn't be enough. I'm searching the login script now.
Update... Found a key I was looking for.
Code: Select all
cookie('netjukebox_hash')
Code: Select all
// +---------------------------------------------------------------------------+
// | Download Album |
// +---------------------------------------------------------------------------+
function downloadalbum($album_id)
{
global $cfg;
authenticate('access_download');
ini_set('max_execution_time', $cfg['download_timeout']);
$test = mysql_query('SELECT relative_file FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '" ORDER BY relative_file');
while($file = mysql_fetch_array($test))
{
$filename = mysql_query('SELECT artist, title FROM track WHERE relative_file = "' . mysql_real_escape_string($file[0]) .'"');
$name = mysql_fetch_array($filename);
$file2 = $cfg['media_dir'] . $file[0];
$filelist .= '"'. $file2 .'" ';
};
$albumname = mysql_query('SELECT artist, album FROM album WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
$albumname2 = mysql_fetch_array($albumname);
$combined2 = $albumname2[0] ." - ". $albumname2[1] .".zip";
set_time_limit(0);
$downloadcmd = 'C:/Codecs/7za.exe a -mx0 -tzip "'. $cfg['tempdir'] . cookie('netjukebox_hash') .'/'. $combined2 .'" '. $filelist;
@exec($downloadcmd);
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . $combined2 . '"');
header('Content-Transfer-Encoding: binary');
$file = $cfg['tempdir'] . cookie('netjukebox_hash') .'/'. $combined2;
if (version_compare(phpversion(), '5.0.0', '>='))
{
$filehandle = @fopen($file, 'rb') or exit();
while (!feof($filehandle))
echo fread($filehandle, 1024 * 1024);
fclose($filehandle);
}
else
@readfile($file);
function rmdirr($dir) {
if($objs = glob($dir."/*")){
foreach($objs as $obj) {
is_dir($obj)? rmdirr($obj) : unlink($obj);
}
}
rmdir($dir);
}
rmdirr($cfg['tempdir'] . cookie('netjukebox_hash') .'/');
}