[Mapbender-dev] print for A2

Lars-Hendrik Schneider schneider at terrestris.de
Thu Sep 7 04:09:35 EDT 2006

Hi Astrid, hi folks,

Astrid Emde schrieb:
> Hi developer,
> I would like to check in the print modules again. I extended it for the 
> A2-print.
> Lars  - you are working on this modul as well. Do you mind? or can you 
> checkin your changes aswell?

I just discussed some experiences with Astrid personally and I thought 
that it would be helpful to keep all informed.

I am currently working on a way to setup some batch printing for a 
customer. These are the circumstances:

- We need a logging of the prints for billing
- The prints are made from high quality raw data (50GB and more) and the 
pdf print takes a long time to get all its input.
- The pdf files reach a large size (several MB) afterwards
- The pdf files must not be world readable and have to be stored outside 
the http directory of mapbender.

My idea was:

- Someone triggers a print. All information for the print are stored in 
the database (mb_log or somewhere else). The unique id of the dataset is 
passed to the print module. Depending on the requested format (e.g. A2 
-> batch, A4 -> deliver directly using download or stream) the print 
module either starts to deliver directly or triggers a call on the 
commandline (with & to detach from the running php). The idea is to set 
a default delivery method (either download or stream) and then set a 
variable containing all formats that have to be processed from command 
line. If this variable contains all formats, download or stream are 
disabled at all.

- If the print has to be detached the module gives out a "Your print 
will be processed and a link will be sent to your email address". 
Therefore this batch processing should only be available to users with a 
given email address of course.

- The script is then called again with the unique id of the print and 
with an additional parameter "batch"  which causes the print module to 
run through, store the file outside the http dir and send a link to the 
users email address.


"You or someone using your account has requested a high quality print 
from Mapbender: Please use the following link to download the requested 
file: http://the.url.com/mapbender/print/deliver.php?sid=123456" while 
the sid refers to the filename of the print (123456.pdf or with a hidden 
secret like 123456_mysecret.pdf) in order to make it more difficult to 
guess filenames.

I added a function to get the creation date of the file first in order 
to disable downloads after a certain time (e.g. "This download is only 
valid for 24 hours.").

- Security: I think it is not really necessary to ask for username and 
password again - normally the email address should be enough as 
credential and makes it easier to implement. The filenames can be made 
"more unique" by adding a secret which is hidden from the user. The 
files are stored outside the http dir and cannot be reached by robots 
and search engines. Older files can be deleted if the timeout is reached 
for keeping the system tidy.

As a teaser - here is the (so far) code for delivery. (A "delete all 
files which are older than ..." might be added here which makes a 
further cron job obsolete and keeps the code more system independent).

By the way - there should be a routine for keeping all tmp dirs clean 
(remember the sld garbage). I talked to Uli about it and we thought of 
setting up a batch dir in mapbender for such routines - but this is sort 
of off topic btw.

The code:


$dir = NATMPDIR."/";

$type = 'application/pdf';
$ext = '.pdf';
$filename_pub = "mapbender.org_BatchPrint.pdf";

$time_dl_switch = "off";
$time_dl = "86400"; // time in seconds, how long it is available for 

$message_403 = "Download disabled, timelimit exceeded.";
$message_404 = "File does not exist. Aborting.";
$message_410 = "File does no longer exist. Aborting.";

function makeDownload($file,$dir,$type,$ext,$filename_pub) {

     header("Content-Type: $type");

     header("Content-Disposition: attachment; 



if ($time_dl_switch = "on") {
$now = time();

if (file_exists($dir.$_GET['sid'].$ext)) {
    	$ftime = filemtime($dir.$_GET['sid'].$ext);

	else {
	echo $message_404;

$diff = bcsub($now,$ftime);

if ($diff >= $time_dl) {
	echo $message_403;
	else {

	if(!empty($_GET['sid']) && !preg_match('=/=', $_GET['sid'])) {
		if(file_exists ($dir.$_GET['sid'].$ext))     {
	else {
	echo $message_410;

elseif ($time_dl_switch == "off") {

	if(!empty($_GET['sid']) && !preg_match('=/=', $_GET['sid'])) {
		if(file_exists ($dir.$_GET['sid'].$secret.$ext))     {
	else {
	echo $message_410;







terrestris Till Adams & Hinrich Paulsen GbR

Lars-Hendrik Schneider

Siemensstr. 8
D-53121 Bonn

Telefon: +49 (0)228 - 962 899 53
Fax: +49 (0)228 - 962 899 57
E-Mail: schneider at terrestris.de
Internet: http://www.terrestris.de


More information about the Mapbender_dev mailing list