发新话题
打印

perl如何内嵌html

perl如何内嵌html

问:我现在有一个html的网页代码,要将其改为perl程序,如果只是单纯在其第一行加上"#!../perl/bin/perl",并将文件后缀名改为.cgi,会出现错误提示"You don't have permission to access /test/index.cgi on this server."。换句话说:后缀名为.cgi的perl里如何包含html代码?
答:sub html_html

{

print "Content-type: text/html\n\n";

print <
#这里输出html

eof

exit;

}
问:加了以后果然可以,但里面的图片"resource/Top.gif"却不能显示,图片路径绝对是正确的,如:resource/top.gif
答:用相对路径,最好做一个安装文件setup.cgi
在你的这个文件中:

require "setup.cgi";
然后这样调用:lt;img src="$gif/top.gif">
setup.cgi文件中有这一行:

$gif='http://your url/resource';  #图片的URL路径,注意是单引号而不是双引号。
这样用相对路径应该可以了。

TOP

发新话题