extranet/www/page2pdf.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2009-03-03 16:36:37 +00:00
<?php
function topdf($filename, $options = "") {
// Write the content type to the client...
header("Content-Type: application/pdf");
header("Content-Disposition: inline; filename=\"generic.pdf\"");
//header("Content-Disposition: attachement; filename=\"generic.pdf\"");
flush();
// Run HTMLDOC to provide the PDF file to the user...
// Use the --no-localfiles option for enhanced security!
// Use ulimit to limit the maximum amount of memory used by each instance!
passthru("ulimit -m 16384 -t 5; htmldoc --no-localfiles -t pdf14 --quiet --jpeg --webpage $options '$filename'");
}
function bad_url($url) {
// See if the URL starts with http: or https:...
if (strncmp($url, "http://", 7) != 0 &&
strncmp($url, "https://", 8) != 0)
{ return 1; }
// Check for bad characters in the URL...
$len = strlen($url);
for ($i = 0; $i < $len; $i ++) {
if (!strchr("~_*()/:%?+-&@;=,$.", $url[$i]) &&
!ctype_alnum($url[$i]))
{ return 1; }
}
return 0;
}
//Start...
$url = $_REQUEST['url'];
//Construire le titre du fichier PDF en fonction des param<61>tres fournis
if (bad_url($url)) {
print("<html><head><title>Bad URL</title></head>\n"
."<body><h1>Bad URL</h1>\n"
."<p>The URL <b><tt>$url</tt></b> is bad.</p>\n"
."</body></html>\n");
} else {
topdf($url);
}
?>