I am trying to upload a file on localhost server (Apache 2.2 on Linux platform), but I am getting Internal Server Error 500.
Server is running fine (as I am able to print all environment variables through CGI script), I am unable to find my way even after lot of googling.
This is my HTML code:
<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>
This is my cgi script that is being placed at /var/www/cgi-bin where I have given full permission to this file.
#!/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>
Please somebody provide me a hint to solve the above simple problem. Thanks.