Download Album

User avatar
wbartels
netjukebox developer
Posts: 872
Joined: Thu Nov 04, 2004 3:12 pm
Location: Netherlands
Contact:

Post by wbartels »

Thanks again for all the code.
I really appreciate that :)
lylos wrote:You said with the new version that there will be a session_id tracked in the mysql database. Is this going to be deleted after a timeout or whenever the user leaves the website? If so, then the deletion of the temp dirs can be tied with this.
I'm now doing the final test of netjukebox 3.76.
(creating new database and incremental update database from an older version)
I would say look for yourself today or tomorrow when it will be released.
I have made a temp() function in the include/initialize.inc.php file.
If you have improvements I'm glad to hear.
User avatar
wbartels
netjukebox developer
Posts: 872
Joined: Thu Nov 04, 2004 3:12 pm
Location: Netherlands
Contact:

Post by wbartels »

I have a improvement for your script.
When adding the Content-Length header it will give a progress status while downloading.

Code: Select all

@exec($downloadcmd); 
$file = $cfg['tempdir'] . cookie('netjukebox_hash') .'/'. $combined2; 
header('Content-Type: application/force-download'); 
header('Content-Disposition: attachment; filename="' . $combined2 . '"'); 
header('Content-Transfer-Encoding: binary'); 
header('Content-Length: ' . filesize($file));
User avatar
wbartels
netjukebox developer
Posts: 872
Joined: Thu Nov 04, 2004 3:12 pm
Location: Netherlands
Contact:

Post by wbartels »

Here is my working version so far.
It is made fore netjukebox 3.76 (new temp function)

Code: Select all

//  +---------------------------------------------------------------------------+ 
//  | Download Album                                                            | 
//  +---------------------------------------------------------------------------+ 
function downloadalbum($album_id) 
{ 
global $cfg; 
authenticate('access_download', true, false);
ini_set('max_execution_time', $cfg['download_timeout']);
temp('create');

$list = $cfg['temp'] . $cfg['slash'] . $album_id . '.txt';
$filehandle = fopen($list, 'w');
$query = mysql_query('SELECT artist, title, relative_file FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '" ORDER BY relative_file');
while($track = mysql_fetch_array($query))
	{
	fwrite($filehandle, $cfg['media_dir'] . $track['relative_file'] . "\r\n");
	}
fclose($filehandle);

$query		= mysql_query('SELECT artist, album FROM album WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
$album		= mysql_fetch_array($query);
$file		= $cfg['temp'] . $cfg['slash'] . $album_id . '.zip';

$cmd = 'D:\Console\Codec\7za.exe a -mx0 -tzip "' . $file . '" "@'. $list . '"'; 
@exec($cmd);

header('Content-Type: application/force-download');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' . $album['artist'] . ' - ' . $album['album'] . '.zip"');
header('Content-Length: ' . filesize($file));
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);
temp('delete');
}
User avatar
wbartels
netjukebox developer
Posts: 872
Joined: Thu Nov 04, 2004 3:12 pm
Location: Netherlands
Contact:

Post by wbartels »

Here an updated version:

Code: Select all

//  +---------------------------------------------------------------------------+ 
//  | Download Album                                                            | 
//  +---------------------------------------------------------------------------+ 
function downloadalbum($album_id) 
{ 
global $cfg; 
authenticate('access_download', true, false);
ini_set('max_execution_time', $cfg['download_timeout']);
temp('create');

$list = $cfg['temp'] . $cfg['slash'] . $album_id . '.txt';
$filehandle = fopen($list, 'w');
$query = mysql_query('SELECT artist, title, relative_file FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '" ORDER BY relative_file');
while($track = mysql_fetch_array($query))
	{
	$source = $cfg['media_dir'] . $track['relative_file'];
	if ($cfg['windows'])
		$source = str_replace('/', '\\', $source);
	fwrite($filehandle, $source . "\r\n");
	}
fclose($filehandle);

$query		= mysql_query('SELECT artist, album FROM album WHERE album_id = "' . mysql_real_escape_string($album_id) . '"');
$album		= mysql_fetch_array($query);
$file		= $cfg['temp'] . $cfg['slash'] . $album_id . '.zip';

$cmd = 'D:\Console\Codec\7za.exe a -mx0 -tzip "' . $file . '" "@'. $list . '"'; 
@exec($cmd);

$filename = $album['artist'] . ' - ' . $album['album'];
$filename = EncodeEscapeCharacters($filename);
header('Content-Type: application/force-download');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' . $filename . '.zip"');
header('Content-Length: ' . filesize($file));
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);
temp('delete');
}
User avatar
wbartels
netjukebox developer
Posts: 872
Joined: Thu Nov 04, 2004 3:12 pm
Location: Netherlands
Contact:

Post by wbartels »

The current 7zip uses DOS encoding for the list file.
This gives a problem when zipping files with high character in it.
The good news is that 7zip will release a version witch supports high characters in a couple of months.

In the meantime it is possible to encode the filename to CP850 in the list file.
On my system it works on almost all files.

Here is the fix:

Code: Select all

$list = $cfg['temp'] . $cfg['slash'] . $album_id . '.txt';
$filehandle = fopen($list, 'w');
$query = mysql_query('SELECT relative_file FROM track WHERE album_id = "' . mysql_real_escape_string($album_id) . '" ORDER BY relative_file');
while($track = mysql_fetch_array($query))
	{
	$source = $cfg['media_dir'] . $track['relative_file'];
	if ($cfg['windows'])
		$source = str_replace('/', '\\', $source);
	$source = iconv('ISO-8859-1', 'CP850', $source);
	fwrite($filehandle, $source . "\r\n");
	}
fclose($filehandle);
pht3k

just a comment

Post by pht3k »

hi,

i haven't really looked carefully the replys but i wanted to share something that might be usefull. the 4images php script shows a button that permit to download a zip file with every selected image. so it makes a zip file on the fly with multiple image files. (maybe i added a mod to the script to have this functionnality ; i can't remember). if you want to have a look to this script, folow this link :

http://www.4homepages.de/4images/download.php

my 2 cents,
pht3k
User avatar
wbartels
netjukebox developer
Posts: 872
Joined: Thu Nov 04, 2004 3:12 pm
Location: Netherlands
Contact:

Re: just a comment

Post by wbartels »

pht3k wrote:hi,

i haven't really looked carefully the replys but i wanted to share something that might be usefull. the 4images php script shows a button that permit to download a zip file with every selected image. so it makes a zip file on the fly with multiple image files. (maybe i added a mod to the script to have this functionnality ; i can't remember). if you want to have a look to this script, folow this link :

http://www.4homepages.de/4images/download.php

my 2 cents,
pht3k
I will make use of 7zip because it is more than 10 times faster than a PHP script.

7zip is working on high character support in the list file.
When this is ready I will implement album downloading in netjukebox.
Locked