After some investigating, I think I’ll try the phptools script.
It means I’ll set a link in the gallerypicturetpl.html like this
<a href="[(site_url)]assets/snippets/forceDownload/download_image.php?file=[+maxigallery.picture.filename+]">
All would be easy if all images where stored in the same folder, but it’s not the case they’re stored in ID based folders which means I have to get the value of the $path_to_gal from Maxigallery as a parameter for the force-download script.
<?php
// this is a relative path from this file to the
// directory where the download files are stored.
$path='...here_the_path_to_gal...';
// first, we'll build an array of files that are legal to download
chdir($path);
$files=glob('*.*');
// next we'll build an array of commonly used content types - David : I shortened the list to just images
$mime_types=array();
$mime_types['bmp'] ='image/bmp';
$mime_types['gif'] ='image/gif';
$mime_types['jpe'] ='image/jpeg';
$mime_types['jpeg'] ='image/jpeg';
$mime_types['jpg'] ='image/jpeg';
$mime_types['tif'] ='image/tiff';
$mime_types['tiff'] ='image/tiff';
// did we get a parameter telling us what file to download?
if(!$_GET['file']){
// if not, create an error message
$error='No file specified to download';
}elseif(!in_array($_GET['file'],$files)){
// if the file requested is not in our array of legal
// downloads, create an error for that
$error='Requested file is not available';
}else{
// otherwise, get the file name and its extension
$file=$_GET['file'];
$ext=strtolower(substr(strrchr($file,'.'),1));
}
// did we get the extension and is it in our array of content types?
if($ext && array_key_exists($ext,$mime_types)){
// if so, grab the content type
$mime=$mime_types[$ext];
}else{
// otherwise, create an error for that
$error=$error?$error:"Invalid MIME type";
}
// if we didn't get any errors above
if(!$error){
// if the file exists
if(file_exists("$file")){
// and the file is readable
if(is_readable("$file")){
// get the file size
$size=filesize("$file");
// open the file for reading
if($fp=@fopen("$file",'r')){
// send the headers
header("Content-type: $mime");
header("Content-Length: $size");
header("Content-Disposition: attachment; filename=\"$file\"");
// send the file content
fpassthru($fp);
// close the file
fclose($fp);
// and quit
exit;
}
}else{ // file is not readable
$error='Cannot read file';
}
}else{ // the file does not exist
$error='File not found';
}
}
// if all went well, the exit above will prevent anything below from showing
// otherwise, we'll display an error message we created above
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Image Download</title>
</head>
<body>
<h1>Download Failed</h1>
<?php
if($error) print "<p>The error message is: $error</p>\n";
?>
</body>
</html>
What do I do then ?
Declare [tt]global $modx;[/tt]
then include the [tt]maxigallery.class.inc.php[/tt] file and set [tt]$path_to_gal = $mg->path_to_gal;[/tt] ?
If someone could help me get started, I’d appreciate it !
Edit : Just thinking... since the folders pictures are in are based on the gallery’s ID, couldn’t I get the ID using $modx->documentIdentifier ?