1

I'm using PHP's ZipArchive Class to add generated PDF files to a zip archive. The generated PDFs are stored in C:\pdfgenerator (not my www directory), while the zip file itself is created and stored in C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\med (the directory where my web site lives).

Here is the code I use to create the PDF/Zip and attempt to store the PDF within the Zip:

/* build zip & directory for PDFs */
$zip = new ZipArchive;
$time = microtime(true);

if($res = $zip->open("pdf/mf-pdfs_" . $time . ".zip", ZipArchive::CREATE) === TRUE) {
    echo "created";
    } else {
    echo "failed";
    }


$num = 0;
while($row = mysql_fetch_array($result)) {

    /* associate a random # assigned to each PDF file name */
    $num++;
        include($form);
    $rand = rand(1,50000);
     $file_num = $num * $rand;

    $fo = fopen('c:\\pdfgenerator\\mf_pdf-' . $time . '-' . $file_num . '.html', 'w') or die("can't open file");

    fwrite($fo, $output);
    echo shell_exec('c:\wkhtmltopdf\wkhtmltoimage c:\\pdfgenerator\\mf_pdf-' . $time . '-' . $file_num . '.html c:\\pdfgenerator\\mf_pdf-' . $time . '-' . $file_num . '.jpeg');

    /* the follow uses ghost script to execute the ImageMagick convert command from cmd.exe */
    $magick_dir = 'C:\imagemagick' ; // install IM in short DOS 8.3 compatible path
    $send_cmd=$magick_dir .'\convert c:\\pdfgenerator\\mf_pdf-' . $time . '-' . $file_num . '.jpeg -resize "1710x2200^!" c:\\pdfgenerator\\mf_pdf-' . $time . '-' . $file_num . '.jpeg' ;

    $result = shell_exec($send_cmd);
    $send_cmd=$magick_dir .'\convert c:\\pdfgenerator\\mf_pdf-' . $time . '-' . $file_num . '.jpeg c:\\pdfgenerator\\mf_pdf-' . $time . '-' . $file_num . '.pdf';
    $result = shell_exec($send_cmd) ;

    /* EO ghostscript code */

/* add the newly generated files to the Zip Archive */
    if ($res === TRUE) {
    //echo "RESULT TRUE...";
     if($zip->addFile('c:/pdfgenerator/mf_pdf-' . $time . '-' . $file_num . '.pdf','c:/pdfgenerator/mf_pdf-' . $time . '-' . $file_num . '.pdf') === TRUE) {
        echo "addded";
        } else {
        echo "not added";
        }
    //echo "FILE ADDED!";
    } 
 /* EO Zip Archive */

}

When I had the PDFs and Zip file being stored within the same parent directory (/med), the script worked perfectly fine.

Is it possible to use the Zip Archive Class and add files to the Zip that do not live within the same parent directory? I've tried numerous changes but haven't been able to get the AddFile to work properly. Am I missing something?

stoopkid1
  • 114
  • 1
  • 1
  • 9

1 Answers1

1

Sounds like it is an issue with the permissions of the user that Apache is running as

Finding out what user Apache is running as in windows?

The Apache user needs to have at least read access to C:\pdfgenerator

Community
  • 1
  • 1
Andres Lowrie
  • 170
  • 3
  • 10
  • thanks for pointing out the possibility of it being a permissions problem. since i created that c:\pdfgenerator manually as opposed to through PHP and the mkdir() functionality, the internet/apache user had not been granted modify permission. setting the internet user's permission to "modify" successfully fixed my issue. – stoopkid1 Jan 24 '13 at 22:04