简体   繁体   English

PHP ZipArchive :: AddFile来自其他目录问题

[英]PHP ZipArchive::AddFile from different directory issue

I'm using PHP's ZipArchive Class to add generated PDF files to a zip archive. 我正在使用PHP的ZipArchive类将生成的PDF文件添加到zip存档中。 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). 生成的PDF存储在C:\\ pdfgenerator(不是我的www目录)中,而zip文件本身是创建并存储在C:\\ Program Files \\ Apache Software Foundation \\ Tomcat 6.0 \\ webapps \\ med(我的网站所在的目录)中生活)。

Here is the code I use to create the PDF/Zip and attempt to store the PDF within the Zip: 这是我用来创建PDF / Zip并尝试将PDF存储在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. 当我将PDF和Zip文件存储在同一父目录(/ med)中时,该脚本可以正常工作。

Is it possible to use the Zip Archive Class and add files to the Zip that do not live within the same parent directory? 是否可以使用Zip存档类,并将不在同一父目录中的文件添加到Zip中? I've tried numerous changes but haven't been able to get the AddFile to work properly. 我已经尝试了无数次更改,但无法使AddFile正常工作。 Am I missing something? 我想念什么吗?

Sounds like it is an issue with the permissions of the user that Apache is running as 听起来像Apache的用户权限问题

Finding out what user Apache is running as in windows? 找出Apache在Windows中以何种身份运行用户?

The Apache user needs to have at least read access to C:\\pdfgenerator Apache用户至少需要具有对C:\\ pdfgenerator的读取权限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM