Download complete album als ZIP - Page 8 Download complete album als ZIP - Page 8
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Download complete album als ZIP

Started by Finswimmer, January 18, 2012, 09:33:00 AM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

FrA1l3

Hi!

Please, ¿Anyone can update this plugin to CPG 1.6.3?
I can't make working well with this update code:

Thank you in advance!


<?php

if (!USER_ID) {
    
cpg_die(ERROR$lang_errors['access_denied'], __FILE____LINE__);
}

error_reporting(E_ALL);
ini_set('display_errors''1');

define('IN_COPPERMINE'true);
define('THUMBNAILS_PHP'true);
define('INDEX_PHP'true);

include(
'include/archive.php');

echo 
'<p>Deleting old zip files...</p>';
$dir $CONFIG['fullpath'].'edit/';

if (
$handle opendir($dir)) {
    while (
false !== ($entry readdir($handle))) {
        if (
preg_match('/^album_[0-9a-f]+.zip$/'$entry) && filemtime($dir.$entry) < time() - CPG_DAY) {
            
unlink($dir.$entry);
        }
    }
    
closedir($handle);
}

echo 
'<p>Creating file list...</p>';
$filelist = array();
$aid $superCage->get->getInt('aid');
get_meta_album_set(0);
$query "SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} AS pictures , (SELECT keyword FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '" $aid "' ) AS keyword, {$CONFIG['TABLE_ALBUMS']} AS r $RESTRICTEDWHERE AND r.aid = pictures.aid AND (pictures.aid = '" $aid "' OR ( keyword.keyword <> '' AND CONCAT(';', keywords, ';') LIKE CONCAT('%;', keyword.keyword, ';%')))";
$result cpg_db_query($query);
$rowset cpg_db_fetch_rowset($result);

foreach (
$rowset as $row) {
    
$fileentry $row['filepath'].$row['filename'];
    
$filelist[] = $fileentry;
}
$resultado cpg_db_query("SELECT title, aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '" $aid "'" );
if (
cpg_db_num_rows($resultado) > 0) {
$CURRENT_ALBUM_DATA cpg_db_fetch_assoc($resultado);
}
cpg_db_free_result($resultado);
$album $CURRENT_ALBUM_DATA['title'];

echo 
'<p>Creating zip file...</p>';
$filename 'edit/' $album '.zip';

$zip = new ZipArchive(); 
$zip->open$filenameZipArchive::CREATE ); 
$zip->addFromString$filelist$filelist );
$zip->close(); 

// Stream the file to the client 
header("Content-Type: application/zip"); 
header("Content-Length: " filesize($file)); 
header("Content-Disposition: attachment; filename=\"'$filename'\""); 
readfile($filename); 
unlink($filename);

echo 
'<p>Downloading...</p>';

ob_end_clean();

header('Location: ' $CONFIG['site_url'] . $CONFIG['fullpath'] . $filename);

?>

ron4mac

The original plugin works with CPG 1.6.03 without problem.

The only change in your file that I see could be an issue is using ZipArchive(). Your new PHP version (7) may not have the ZIpArchive extension enabled.

FrA1l3

Thank you for the reply!

Before publishing my message yesterday I made sure that my flags are still correct, and PHP has enabled the ZIP extension in Cpanel.
I have also tried with PHP 7.0, 7.1 and 7.2 versions (cpanel flags.png)

As you can see in the image, the original plugin gives me this error (error.png)

So I went to review the documentation of the function:
http://php.net/manual/en/book.zip.php

And I see that there is the ZipArchive () method, which is what I've been testing. But it does not work either.
In any case, I have reinstalled the original plugin, but the same error of the first capture still comes out

Thanks in advance!

ron4mac

It would seem that include/archive.php is not being included.

At the top of zip.php in the plugin, change:
include('include/archive.php');
to:
require_once 'include/archive.php';

That may reveal more of the situation.

FrA1l3

It's true, I do not know where that file is or why it references but I do not have it on my server.

I have tried several solutions rereading the whole thread and searching the internet and nothing. I do not know why the plugin stopped working.

The new error with the require_once is:
Quote
Fatal error: require_once(): Failed opening required 'include/archive.php' (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /xxxxxxx/plugins/albumdownload/zip.php on line 10

thanks in advance

ron4mac

It would be easy for you to do a quick re-install.
http://forum.coppermine-gallery.net/index.php/topic,79013.msg383037.html#msg383037

I'm recommending that people use the bottom (red) choice for what to install to get all the latest changes.

FrA1l3

Quote from: ron4mac on March 12, 2018, 01:10:43 PM
It would be easy for you to do a quick re-install.
http://forum.coppermine-gallery.net/index.php/topic,79013.msg383037.html#msg383037

I'm recommending that people use the bottom (red) choice for what to install to get all the latest changes.

Thank you! Thank you! Thank you!  ;D ;D ;D ;D

It had not occurred to me to reinstall. I've done it as you said and now it works perfect again.
I owe you a beer (or two), best regards!!

Johnfromhere

I have read all the posts in this thread but may have got lost! (Download complete album as a ZIP file)

Can you please tell me which version of the plugin to download and install.

Also - can it be limited to certain 'groups' of users (it would appear that it can?) and certain albums?

I am running cpg1.5.46.

Many thanks.

John.


Johnfromhere

Please ignore my previous posting. I had another read,  installed it and it works great. 

Many thanks.

It would be nice if it wrote the details of which user downloaded which album to a log file (are we ever satisfied?  :);D)

Cheers John.

FrA1l3

#149
Quote from: Johnfromhere on March 18, 2018, 11:19:35 PM
Please ignore my previous posting. I had another read,  installed it and it works great. 

Many thanks.

It would be nice if it wrote the details of which user downloaded which album to a log file (are we ever satisfied?  :);D)

Cheers John.

Hello John!
You can add a simple mod to the zip.php file to create your personal download's log.
I will try quickly this code and works perfect!

<?php
// FrA1l3 - Register DOWNLOADS
$file_name "././logs/access.log.php";
$message "ALBUM DOWNLOAD: The user '" USER_NAME "' has downloaded the album '$album'.";

 if(
$file fopen($file_name"a"))
    {
        
fwrite($filedate("d m Y H:m:s") . " " $message "\n");
        
fclose($file);
    } 
// END modification LOG
?>


To view the log simply go to  http://your_coppermine_url/viewlog.php (1.png)

Keep in mind that the modification is on my own modified version of the plugin, worth the redundancy.
That's why I use the variable $album again for the log file too.

regards!

Johnfromhere

Thanks for that.

I modded zip.php and it works fine except that it doesn't give the name of the album which was downloaded.

I don't know much about php but I assume that the $album variable has not been given a value?

I should be most grateful if you could offer a fix.

Many thanks.

John.

FrA1l3

Quote from: Johnfromhere on March 19, 2018, 07:02:47 PM
Thanks for that.

I modded zip.php and it works fine except that it doesn't give the name of the album which was downloaded.

I don't know much about php but I assume that the $album variable has not been given a value?

I should be most grateful if you could offer a fix.

Many thanks.

John.

Good night John,
Here is the piece of code where I retrieve the name of the album and assign it to the variable, put this code before the previous one and everything works for you.
If you have any problems, tell me.


<?php
$result 
cpg_db_query("SELECT title, aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '" $aid "'" );
if (
cpg_db_num_rows($result) > 0) {
$CURRENT_ALBUM_DATA cpg_db_fetch_assoc($result);
}
cpg_db_free_result($result);
$album $CURRENT_ALBUM_DATA['title'];
?>



regards,
George

Johnfromhere

Many thanks, George.

I modded zip.php and tested it but the album name is still missing.

Just to check, here is are the lines I inserted at the beginning of zip.php:-
// FrA1l3 - Register DOWNLOADS
$result = cpg_db_query("SELECT title, aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '" . $aid . "'" );
if (cpg_db_num_rows($result) > 0) {
$CURRENT_ALBUM_DATA = cpg_db_fetch_assoc($result);
}
cpg_db_free_result($result);
$album = $CURRENT_ALBUM_DATA['title'];
$file_name = "././logs/access.log.php";
$message = "ALBUM DOWNLOAD: The user '" . USER_NAME . "' has downloaded the album '$album'.";

if($file = fopen($file_name, "a"))
    {
        fwrite($file, date("d m Y H:m:s") . " " . $message . "\n");
        fclose($file);
    }
// END modification LOG


Cheers.

John.

FrA1l3

Hello @Johnfromhere!

I put the entire zip.php file, please backup first your file and copy all of this quote to the original file (replace all of the code)
It is working well on my server.


application/x-httpd-php zip.php ( PHP script, ASCII text, with very long lines )
<?php

if (!USER_ID) {
    
cpg_die(ERROR$lang_errors['access_denied'], __FILE____LINE__);
}

error_reporting(E_ALL);
ini_set('display_errors''1');

define('IN_COPPERMINE'true);
define('THUMBNAILS_PHP'true);
define('INDEX_PHP'true);

require_once 
'include/archive.php';

echo 
'<p>Deleting old zip files...</p>';
$dir $CONFIG['fullpath'].'edit/';
if (
$handle opendir($dir)) {
    while (
false !== ($entry readdir($handle))) {
//FrA1l3 - file name change
//if (preg_match('/^pictures-[0-9a-f]+.zip$/', $entry) && filemtime($dir.$entry) < time() - 2 * CPG_DAY) {
        
if (preg_match('/^album_[0-9a-f]+.zip$/'$entry) && filemtime($dir.$entry) < time() - CPG_DAY) {
            
unlink($dir.$entry);
        }
    }
    
closedir($handle);
}

echo 
'<p>Creating file list...</p>';
$filelist = array();
$aid $superCage->get->getInt('aid');
get_meta_album_set(0);
$query "SELECT filepath, filename FROM {$CONFIG['TABLE_PICTURES']} AS pictures , (SELECT keyword FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '" $aid "' ) AS keyword, {$CONFIG['TABLE_ALBUMS']} AS r $RESTRICTEDWHERE AND r.aid = pictures.aid AND (pictures.aid = '" $aid "' OR ( keyword.keyword <> '' AND CONCAT(';', keywords, ';') LIKE CONCAT('%;', keyword.keyword, ';%')))";
$result cpg_db_query($query);
$rowset cpg_db_fetch_rowset($result);

foreach (
$rowset as $row) {
    
$fileentry $row['filepath'].$row['filename'];
    
$filelist[] = $fileentry;
}

//FrA1l3 - query to search album name for filename
/*****************************************************/
$resultado cpg_db_query("SELECT title, aid FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid = '" $aid "'" );
if (
cpg_db_num_rows($resultado) > 0) {
$CURRENT_ALBUM_DATA cpg_db_fetch_assoc($resultado);
}
cpg_db_free_result($resultado);
$album $CURRENT_ALBUM_DATA['title'];
/*****************************************************/

echo '<p>Creating zip file...</p>';
//FrA1l3 - change filename to albumname
//$filename = 'edit/pictures-' . uniqid(null) . '.zip';
$filename 'edit/' $album '.zip';
$zip = new zip_file($filename);

$options = array(
    
'basedir'    => "./{$CONFIG['fullpath']}",
    
'recurse'    => 0,
    
'storepaths' => 0,
);

$zip->set_options($options);
$zip->add_files($filelist);
$zip->create_archive();

echo 
'<p>Downloading...</p>';

// FrA1l3 - Register DOWNLOADS
$file_name "././logs/access.log.php";
$message "ALBUM DOWNLOAD: The user '" USER_NAME "' has downloaded the album '$album'.";

 if(
$file fopen($file_name"a"))
    {
fwrite($filedate("d m Y H:m:s") . " " $message "\n");
        
fclose($file);
    } 
// END modification LOG
ob_end_clean();

header('Location: ' $CONFIG['site_url'] . $CONFIG['fullpath'] . $filename);

?>



best regards

Johnfromhere

Many thanks, George.

There were several differences between your file and the one I had as zip.php.

I have now replaced it with your version and it works fine!

Many thanks.

John.

JonPurpleHaze

Hello, I had this plugin working with CPG 1.6.07, I just updated to 1.6.08 and it's not working anymore, I now receive this message, somewhat edited for site information:

Deleting old zip files...

Creating file list...

Creating zip file...

Fatal error: Uncaught Error: Call to undefined method zip_file::archive() in /home/cpg/include/archive.php:580 Stack trace: #0 /home/cpg/plugins/albumdownload/zip.php(38): zip_file->__construct('edit/pictures-5...') #1 /home/cpg/index.php(75): include_once('/home/...') #2 {main} thrown in /home/cpg/include/archive.php on line 580

Wondering if anyone has it working with 1.6.08, I might have edited some things based on suggestions in this thread to get it to work in 1.6.07 but I don't remember.
File check mentions that archive.php was changed since 1.6.07, here is line 580 and 581:

    $this->archive($name);
    $this->options['type'] = "zip";

Thank You

ron4mac

#156
Our apologies ...
User submitted changes were made that were apparently not fully tested.

Please replace include/archive.php with the attached (unzipped) file.

Corrected file will be in next release (1.6.09).

JonPurpleHaze

Quote from: ron4mac on March 27, 2020, 02:33:06 PM
Our apologies ...
User submitted changes were made that were apparently not fully tested.

Please replace include/archive.php with the attached (unzipped) file.

Corrected file will be in next release (1.6.09).
It's working again on 1.6.08!
I must mention that I'm very surprised and impressed that I even received a response to my post which was over 2 years since the last one and about a plugin that was releases for cpg 1.5.

Thank You All!

exekutive

I'm getting an error when installing this from the plugin manager: " A valid form token could not be found. "
Am I doing something wrong?