Archive::Zip、EBook::Epub和IIS6 - "desiredCompressionLevel"错误

4
我正在尝试使用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行在addFile子程序中,它使用了三个变量--$fileName,$newName,$compressionLevel--我使用一些打印语句来显示它们在第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

请确保写入的临时目录对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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接