脚本文件名:更改PHP的当前目录
c:\wtserver\www\testclass\index.php
http://localhost = c:\wtserver\www\
代码:
<?php
print getcwd()."<br/>";
chdir(dirname(__FILE__).'\product\\');
print getcwd()."<br/>";
print '<img src="img/1.jpg"/>';
?>
输出是:
c:\wtserver\www\testclass
C:\WTServer\WWW\testclass\product
和图像的位置是:
http://localhost/testclass/img/1.jpg
我需要的是,图像位置应该是:
http://localhost/testclass/product/img/1.jpg
不改变这一行:
print '<img src="img/1.jpg"/>';
感谢。
为什么你不想改变那条线? 'src'中的相对路径对php不起任何作用,但对于html解析客户端:客户端试图相对于包含文档的位置发出get请求。 – deeenes