1

我在 Typo3 站点中包含了一个 PHP 脚本。这个 PHP 脚本会生成 img 标签,它会自动作为imageflow-slider的基础。

图像流文件位于文件夹 /fileadmin/teamtemplate 中。/fileadmin/teamtemplate/images 中的图像。

在 imageflow.js 我有以下参数:

this.defaults =
{
    imagePath:          '',                                    /* Path to the images relative to the reflect_.php script */
    reflectPath:        'fileadmin/teamtemplate/',             /* Path to the reflect_.php script */

在 html 文件的输出中,我有以下内容:

  img  src="./images/1317986502.png" ongdesc="" width="380" height="253" alt="" />

(抱歉,我不知道如何发布 HTML 代码。)Imageflow 创建以下路径,该路径有效:

fileadmin/teamtemplate/reflect3.php?img=./images/1317986502.png

问题如下:

对于 reflect3.php,路径是正确的,因为 (./images) 是可访问的:

-reflect3.php
-images/
--1317986502.png

Imageflow 通常采用 html img src 标签中给出的 URL。reflect3.php 现在可以访问图像,但是在 html 代码中路径错误!

HTML 中的错误,但可以正常工作,因为 reflect3.php 找到了文件
img src="./images/1317986502.png" ongdesc="" width="380" height="253" alt="" />

在 HTML 中正确,但 reflect3.php 找不到文件
img src="./fileadmin/teamtemplate/images/1317986502.png" ongdesc="" width="380" height="253" alt="" />

imageflow.js 中的错误代码

version = (my.reflectionPNG) ? '3' : '2';
src = my.imagePath+node.getAttribute('src',2);
src = my.reflectPath+'reflect'+version+'.php?img='+src+my.reflectionGET;
node.setAttribute('src',src);

my.reflectionGET 应该分解字符串,以便它只需要最后一个 1317986502.png。

工作解决方案:

/* Add 'reflect.php?img=' */
if(my.reflections === true)
{
    version = (my.reflectionPNG) ? '3' : '2';
    if(my.imagePath === "") {
        src = my.imagePath+node.getAttribute('src',2);
        src = my.reflectPath+'reflect'+version+'.php?img='+src+my.reflectionGET;
    } else {
        var imagePath = node.getAttribute('src',2);
        var slash = "/";
        var lastOccurence = imagePath.lastIndexOf(slash);
        var withoutPath = imagePath.substring(lastOccurence, imagePath.length);
        src = my.imagePath+withoutPath;
        src = my.reflectPath+'reflect'+version+'.php?img='+src+my.reflectionGET;
    }
    node.setAttribute('src',src);
}
4

0 回答 0