如何使用CGI Perl在HTML中放置图片? [英] How to put a picture in HTML using CGI Perl?
问题描述
我正在创建一个非常简单的HTML表单。我已经将表格包括在CGI文件中。我正在使用perl脚本。我尝试使用以下CGI脚本在图片中添加图片:
I am creating a very simple HTML form. I have included the form in the CGI file. I am using perl scripting. I have tried to include a picture in my form using the following CGI script:
print "<img src=picture1.jpg style=width:600px;height:300px;>";
这个问题是表单中的图片没有显示,但我不明白当我从浏览器访问表单时,任何错误和其他所有东西都可以正常工作。
The problem with this is that the picture in the form does not show, but I don't get any errors and everything else works fine when I access the form from a browser.
推荐答案
通过查看您的屏幕截图,我猜指定为 src ='picture1.jpg'
的图像源或位置不正确。
From looking at your screenshot, I would guess that the image source or location specified as src='picture1.jpg'
is incorrect.
可能的原因是:
- 服务器上不存在文件
picture1.jpg
- 文件
picture1.jpg
在不同的目录中
- the file
picture1.jpg
does not exist on your server - the file
picture1.jpg
is in a different directory
我敢打赌这是第二个问题。您的CGI脚本很可能位于名为 cgi-bin
的目录中,因此可以使用 src ='picture1.jpg'
您在此 cgi-bin
目录中查找图片。
I bet it's the second problem. Your CGI script is most likely in a directory called like cgi-bin
, so by using src='picture1.jpg'
you look for the picture in this cgi-bin
directory.
您确实确定您的图片位于此处: cgi-bin / picture1.jpg
?
Are you really sure your picture is located here: cgi-bin/picture1.jpg
? Most likely not.
我想图片在其他地方,这意味着您必须为其设置正确的路径,如下例所示:
I guess the picture is somewhere else, which means you have to set the correct path for it as shown in the examples below:
img src='../picture1.jpg'
这意味着向上一级目录查找 picture1.jpg
。
This means "Go one directory level up and look for the picture1.jpg
".
img src='../images/picture1.jpg'
这意味着:上一级目录,在图像
内查找 picture1.jpg
目录。
This means: "Go one directory level up and look for the picture1.jpg
inside the image
directory".
img src='/html/images/picture1.jpg'
这意味着:转到您网站的根目录,找到 html
目录,然后找到图片
目录,最后找到 picture1.jpg
。
This means: "Go to the root directory of your website, find the html
directory, then find the image
directory and finally picture1.jpg
inside.
根据服务器的目录结构调整路径后,该图像应显示在所需位置。 rs,您应该始终正确设置HTML属性的格式。
After you adjusted the path according to your server's directory structure, the image should show up as desired. Furthermore, as mentioned in the other answers, you should always format your HTML attributes properly.
这篇关于如何使用CGI Perl在HTML中放置图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!