(PHP)显示动态目录中的图像
在一台服务器上,我成功地编写了映像,如下所示:(PHP)显示动态目录中的图像,php,xml,image,xhtml,Php,Xml,Image,Xhtml,在一台服务器上,我成功地编写了映像,如下所示: $structure = "./images/$root->City/$root->ZipCode/$root->StreetDirection $root->StreetName/"; file_put_contents("./$structure/$root->StreetNumber $root->StreetDirection $root->StreetName $root->StreetS
$structure = "./images/$root->City/$root->ZipCode/$root->StreetDirection $root->StreetName/";
file_put_contents("./$structure/$root->StreetNumber $root->StreetDirection $root->StreetName $root->StreetSuffix $root->City $root->ZipCode-{$number}.jpeg", $photo['Data']);
然后,我尝试检索并显示相同的图像相同的位置,如下所示,什么也没有发生(断开的图像链接):
$structure=“../images/$City\u R/$Zip\u code\R/$StreetDirection$StreetName$StreetSuffix/$StreetNumber$StreetDirection$StreetName$StreetSuffix$City\R$Zip\u code\R-1”;
$img='
';
回音“$img”;
在测试中,它似乎只在名称大大简化且未指定动态目录时才进行拉取…,实际上,它会一起忽略目录…我不会以这种方式构建src属性。我会在引号外构建它,因为在插入变量值时处理引号内的空格会变得不必要的复杂。 只需在字符串外部使用连接运算符:
$structure = "../images/" . $City_R . "/" . $Zip_Code_R . "/" . $StreetDirection . $StreetName . $StreetSuffix . "/" . $StreetNumber . $StreetDirection . $StreetName . $StreetSuffix . $City_R . $Zip_Code_R-1;
//etc...
注意,您需要为图像源使用URL,并且使用路径。您的src属性最好以“”开头
不要在文件名中使用空格,而要使用破折号,破折号还有一个额外的好处,那就是它对搜索引擎优化也有好处:)可能您使用的是路径,而您需要为img srchechoing“$img”提供一个url?无聊的?我是唯一一个觉得有趣的人吗?
$structure = "../images/" . $City_R . "/" . $Zip_Code_R . "/" . $StreetDirection . $StreetName . $StreetSuffix . "/" . $StreetNumber . $StreetDirection . $StreetName . $StreetSuffix . $City_R . $Zip_Code_R-1;
//etc...