为 PHP/JS 图像幻灯片脚本的 URL 添加静态文件名和扩展名

问题描述 投票:0回答:0

我们正试图获得一个电子邮件签名插件,以“随机”加载循环图像系列中的图像。它需要一个标准的 HTML 标签,它需要一个文件名和“src”的扩展名(它不会使用 src=foo.com/ 或 src=foo.com/file.php 下载它们)。

我有一个有效的 PHP/JS 图像旋转脚本(如下),但是当作为 index.php 上传时,URL 没有图像的文件名和扩展名,所以我无法欺骗电子邮件签名插件来下载/嵌入图片。 我正在寻找以某种方式将“/image.jpg”附加到 URL。

<div id="sig"></div>
     <script>
       var myVar = setInterval(myTimer, 2000);
      var images = [];
      <?php

      // set $dir to your image directory
      $dir = "./images/";

// Open a directory, and read its contents
if (is_dir($dir)){
  if ($dh = opendir($dir)){
    while (($file = readdir($dh)) !== false){
     if (!is_dir($file))
     {
      ?>
      //fill up the JS array with php values
      images.push("<?php echo  $file; ?>");
       <?php
       }
    }
    closedir($dh);
  }
}
?>
function myTimer() {
   var tt=Math.floor((Math.random() * images.length) + 1) - 1;
    document.getElementById("sig").innerHTML  = "<img src='./images/" + images[tt] + "'>";
}
     </script>

尝试过 mod-rewrite,但我不是编码员,必须有更简单的方法。

javascript php static append filenames
© www.soinside.com 2019 - 2024. All rights reserved.