简体   繁体   English

如何将“../”添加到PHP echo img src中

[英]How to add “../” into a PHP echo img src

In my code I show some images in this way: 在我的代码中,我以这种方式显示一些图像:

   ...
     <?php echo '<img src="' .$imageone. '" alt="" /> '?></a></div>
     <?php echo '<img src="' .$imagetwo. '" alt="" /> '?></a></div>
   ...

where $imageone, $imagetwo have path from Mysql database 其中$ imageone,$ imagetwo有来自Mysql数据库的路径

e.g.
$imagesone = "images/exposition/02-05-2017-11-28-00-foto 2_b.JPG";

This code is working in the same place where I have my images folder, but now I need to put the same code in a subfolder page and I'd like to use the same image. 这段代码在我有图像文件夹的地方工作,但现在我需要在子文件夹页面中放入相同的代码,我想使用相同的图像。 So, I need to put dinamically "../" before my varible, something like this: 所以,我需要在我的变量之前加上“../”,类似这样:

...
     <?php echo '<img src="../' .$imageone. '" alt="" /> '?></a></div>
     <?php echo '<img src="../' .$imagetwo. '" alt="" /> '?></a></div>
   ...

but it's not working. 但它不起作用。

Any suggestion? 有什么建议吗?

EDIT This is my solution: 编辑这是我的解决方案:

 if ($images1 != ""){

    $imageone = "../".$images1;

}

if ($images2 != ""){

    $imagetwo = "../".$images2;

}

in this way I fixed my code and it's working! 通过这种方式我修复了我的代码并且它正在工作!

由于你在src之后使用双引号,你可以写下<img src="../$imageone" alt="" />没有必要使用简单的引号来编写变量,因为双引号获取变量号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM