Archive :: Zip,EBook :: Epub和IIS6 - “desiredCompressionLevel”错误

时间:2011-04-29 22:31:43

标签: perl iis-6 zip epub

我正在尝试使用EBook :: Epub将html文件转换为epub。我写的脚本很简单,就像这样:

my $epub = EBook::EPUB->new;
$epub->add_title('title');
$epub->add_author('author');
$epub->add_language('en');
$epub->copy_xhtml("d:/path/to/file.html" , "file.html");
$epub->pack_zip("d:/path/to/file.epub");

当我从命令行运行它时,它运行良好。但是,我正在尝试将其作为CGI脚本部署在IIS6服务器上 - 该服务器运行在相同的计算机上 - 它失败并显示以下消息:

Can't call method "desiredCompressionLevel" on an undefined value at C:/strawberry/perl/vendor/lib/Archive/Zip/Archive.pm line 252.

我检查了Archive.pm,第252行在sub addFile中。它使用了三个变量 - $ fileName,$ newName,$ compressionLevel - 我使用了一些print语句从第252行之前显示它们的值。($ compressionLevel始终为空白)

这是来自命令行,它起作用:

filename: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\7QiqzzNiN5/OPS/file.html 
newname: OPS/Advanced8247.html
filename: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\7QiqzzNiN5/OPS/content.opf 
newname: OPS/content.opf
filename: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\7QiqzzNiN5/OPS/toc.ncx 
newname: OPS/toc.ncx
filename: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\DkgiQN_pTq 
newname: META-INF/container.xml

这是来自服务器,炸弹:

filename: C:\WINDOWS\TEMP\8rxbvOVkKy/OPS/file.html 
newname: OPS/Advanced6575.html
filename: C:\WINDOWS\TEMP\8rxbvOVkKy/OPS/content.opf 
newname: OPS/content.opf
filename: C:\WINDOWS\TEMP\8rxbvOVkKy/OPS/toc.ncx 
newname: OPS/toc.ncx
filename: C:\WINDOWS\TEMP\WqS7fskWi0 
newname: META-INF/container.xml

所以我猜我的问题与写入临时文件的位置有关,但我真的不太了解服务器和Archive :: Zip来搞清楚。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

确保正在写入的临时目录可由IIS运行的IIS用户(IIS_IUSRS和/或IUSR)写入。当您在命令行上运行时,您将以另一个用户身份运行,该用户可能具有写入C:\ Windows \ Temp的权限。我遇到了类似的问题(写入相同的临时目录)并且能够通过将临时目录更改为我的Web应用程序的已发布文档根目录更加本地化的内容来解决问题,该应用程序已在“属性”>下具有正确的权限。安全

在我的情况下,我能够在我的脚本中设置环境变量TMPDIR:

$ENV{TMPDIR} = 'C:\Inetpub\tmp'

并且C:\ Inetpub \ tmp的文件夹权限已更新为IIS_IUSRS和IUSR可写。

以下是来自http://metacpan.org/pod/Archive::Zip的片段,其中讨论了临时文件并设置了$ ENV {TMPDIR}

Archive::Zip::tempFile( [$tmpdir] )

Create a uniquely named temp file. It will be returned open for read/write. If $tmpdir
is given, it is used as the name of a directory to create the file in. If not given, 
creates the file using File::Spec::tmpdir(). Generally, you can override this choice
using the

    $ENV{TMPDIR}

environment variable. But see the File::Spec documentation for your system. Note that 
on many systems, if you're running in taint mode, then you must make sure that 
$ENV{TMPDIR} is untainted for it to be used. Will NOT create $tmpdir if it doesn't 
exist (this is a change from prior versions!). Returns file handle and name:

    my ($fh, $name) = Archive::Zip::tempFile();
    my ($fh, $name) = Archive::Zip::tempFile('myTempDir');
    my $fh = Archive::Zip::tempFile();  # if you don't need the name