English 中文(简体)
通过perl CGI 脚本上传文件
原标题:Uploading file through perl CGI script

我正在尝试将文件上传到本地主机服务器( Linux 平台上的 Apache 2. 2), 但我正在获取“ 坚固” 的内部服务器错误 500

服务器运行良好(因为我可以通过 CGI 脚本打印所有环境变量), 即使经过大量谷歌, 我仍无法找到自己的路 。

这是我的 HTML 代码:

<FORM ACTION="http://localhost/cgi-bin/upload.cgi" METHOD="post" ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="photo">
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit Form">
</FORM>

这是我在/var/www/cgi-bin /var/www/cgi-bin 上放置的Cgi脚本,我已完全允许放入此文件。

#!/usr/bin/perl -w
use CGI;

$upload_dir = "/home/myuser/Desktop/upload";
$query = new CGI;
$filename = $query->param("photo");
$filename =~ s/.*[/\](.*)/$1/;
$upload_filehandle = $query->upload("photo");

open UPLOADFILE, ">$upload_dir/$filename";
while ( <$upload_filehandle> )
{
print UPLOADFILE;
}
close UPLOADFILE;

print $query->header ();

print <<END_HTML;
<HTML>
<HEAD>
<TITLE>Thanks!</TITLE>
</HEAD>
<BODY>
<P>Thanks for uploading your photo!</P>
    <P>Your photo:</P>
<img src="/home/myuser/Desktop/upload/$filename" border="0">
</BODY>
</HTML>

请给我一个提示 解决上面简单的问题 谢谢

问题回答

检查 Apache 错误日志( 通常在 / var/ log/ httpd/ error_ log 中找到) 警告或错误信息。 我怀疑问题在于上传目录不是网络服务器上的 < a href=> http:// www.g- loaded.eu/2008/12/09/ makeing- a- directory- writible- by- the- Webserver/" rel= “ nofolve" >writable

print "Content-type: text/html "; This is a content-type header that tells the receiving web browser what sort of data it is about to receive — in this case, an HTML document. If you forget to include it, or if you print something else before printing this header, you ll get an "Internal Server Error" when you try to access the CGI program.

END_HTML也在EOF失踪。





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签