Archive::Zip、EBook::Epub 和 IIS6 - “desired CompressionLevel”错误

发布于 2024-11-04 08:14:30 字数 1559 浏览 1 评论 0原文

我正在尝试使用 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——并且我使用了一些 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 不太了解,无法弄清楚。有什么想法吗?

I'm trying to convert html files to epub with EBook::Epub. The script I've written is very simple, like so:

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");

When I run this from the command line, it works great. However, I'm trying to deploy it as a CGI script on an IIS6 server--which runs off the same computer--it fails with this message:

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

I checked out Archive.pm, and line 252 is in sub addFile. It's using three variables--$fileName, $newName, $compressionLevel--and I used some print statements to reveal their values from right before line 252. ($compressionLevel is always blank)

This is from the command line, which works:

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

This is from the server, which bombs:

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

So I'm guessing that my problem has to do with where the temp files are being written, but I really don't know enough about servers and Archive::Zip to figure it out. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远山浅 2024-11-11 08:14:30

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

在我的情况下,我能够在脚本中设置环境变量 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

Make sure that the temp directory being written to is writable by the IIS user that IIS runs as (IIS_IUSRS and/or IUSR). When you run on the commandline, you're running as a different user which probably has permissions to write to C:\Windows\Temp. I had a similar problem (writing to that same temp dir) and was able to fix the issue by change the temp directory to something more local to the published document root of my web app which already had the correct permissions under Properties > Security.

In my situation, I was able to set the environment variable, TMPDIR, in my script:

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

and the folder permissions for C:\Inetpub\tmp were updated to be writable by IIS_IUSRS and IUSR.

Here's a snippet from http://metacpan.org/pod/Archive::Zip that talks about temp files and setting $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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文