Imageflow path is wrong because it adds the one from the HTML
I have included a PHP script in a Typo3 site. This PHP script genereates the img tags, which is automatically taken as base for the imageflow-slider.
The imageflow files are in the folder /fileadmin/teamtemplate. The images in /fileadmin/teamtemplate/images.
In the imageflow.js I have the following parameters:
this.defaults =
{
imagePath: '', /* Path to the images relative to the reflect_.php script */
reflectPath: 'fileadmin/teamtemplate/', /* Path to the reflect_.php script */
In the output of the html-file I have the following:
img src="./images/1317986502.png" ongdesc="" width="380" height="253" alt="" />
(Sorry, but I didn't found out how to post HTML code.) Imageflow creates the following path, which is working:
fileadmin/teamtemplate/reflect3.php?img=./images/1317986502.png
The problem is the following:
For the reflect3.php the path开发者_StackOverflow中文版 is correct, because (./images) is accessible:
-reflect3.php
-images/ --1317986502.pngImageflow generally takes the URL given in the html img src tag. reflect3.php can now access the images, but in the html code the path is wrong!
Wrong in HTML, but working because reflect3.php finds the files
img src="./images/1317986502.png" ongdesc="" width="380" height="253" alt="" />Correct in HTML, but reflect3.php cannot find the files
img src="./fileadmin/teamtemplate/images/1317986502.png" ongdesc="" width="380" height="253" alt="" />Faulty code in 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 should explode the string so that it takes only the last 1317986502.png.
Working Solution:
/* 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);
}
精彩评论