Preview Print Jobs (get job from server?)

Ken Tanzer ktanzer at desc.org
Wed Apr 11 13:05:07 PDT 2007


> > Please tell me what I'm missing!  Thanks.
>
> No, you want to put it in /usr/share/doc/cups, with the rest of the
> web content...

Well I made a little progress, but I'm still missing something(s).  Our script works fine if served by Apache (from /var/www/html), but when I copy it to /usr/share/cups, and try to access it as http://localhost:631/preview.php?id=65, my browser says it's loading, but nothing ever happens.  I've posted the script below.

On a side note out of curiousity, how come the web content is kept under /usr/share/doc?  It seems rather nonstandard!

Thanks again for your help.

Ken

Here's our preview.php script.  The output is generated either at the bottom, or at the top in the exit_to_browser function.

<?php

$spool_file_location = '/var/spool/cups';
$spool_file_type = 'ps'; // define to override/avoid magic checking

function exit_to_browser($message)
{
        // FIXME: Exit something browser friendly, with headers and such
        echo('<HTML><HEAD>');
         //header('Content-type: application/x-httpd-php');
         header('Content-type: text/html');
        echo('</HEAD><BODY>')
        echo('We were not able to complete your preview request<br>');
        echo($message);
        echo('</BODY></HTML>');
        exit;
}

$id = $_REQUEST['id'];
$id || exit_to_browser('No ID passed to '.__FILE__);

$spool_pattern='/^d[0]*' . $id . '([-][0-9]+)?$/i';
$spool_files=scandir($spool_file_location);

foreach( $spool_files as $file )
{
        if (preg_match($spool_pattern,$file))
        {
                break;
        }
        $file="";
}

$file || exit_to_browser("Couldn't Find File");
$print_file = "$spool_file_location/$file";

//see if file actually exists
is_readable($print_file) || exit_to_browser(__FILE__ . ' couldn\'t read the requested file to preview.');

//send headers based on file type
$info = pathinfo($print_file);
// these aren't coded with extensions
// PHP documentation references magic functions finfo_file
// Might only be in CVS, or might be a PECL extension

$file_type= $spool_file_type ? $spool_file_type : $info['extension'];
switch ($file_type) {
 case 'ps' :
 case 'pdf' :
         //header('Content-type: application/'.$file_type);
         header('Content-type: application/'.$file_type);
         header('Content-Disposition: attachment; filename="cups_preview_job_' . $id . '.' . $file_type.'"');
         readfile($print_file);
         break;
 default :
         exit_to_browser(__FILE__.' doesn\'t know what to do with files of type '.$file_type);
}

?>






More information about the cups-devel mailing list