PHP图像缓存
我和你有问题。我已经在作者问题页面上发布了这个,但是它不是活动的 Web服务器:NGINX PHP版本:5.5.9-1ubuntu4.14 我收到此错误,最终图像URL已损坏。页面看起来像这样 应该有100个图像显示,但它在第三次死亡。 页面应该与此类似(这是localhost设计) 它正在返回此URL 在mediapage.zips.me和PHP图像缓存,php,caching,Php,Caching,我和你有问题。我已经在作者问题页面上发布了这个,但是它不是活动的 Web服务器:NGINX PHP版本:5.5.9-1ubuntu4.14 我收到此错误,最终图像URL已损坏。页面看起来像这样 应该有100个图像显示,但它在第三次死亡。 页面应该与此类似(这是localhost设计) 它正在返回此URL 在mediapage.zips.me和core之间应该有一个/,但是它是一个本地映像,所以我不明白为什么它甚至需要主机名 我是怎么做的 在每个页面的顶部,我调用另一个包含类设置的页面 <
core
之间应该有一个/
,但是它是一个本地映像,所以我不明白为什么它甚至需要主机名
我是怎么做的
在每个页面的顶部,我调用另一个包含类设置的页面
<?php
//Calls the php-image things
include 'test.php';
?>
insidetest.php
<?php
require_once 'core/classes/ImageCache.php';
$imagecache = new ImageCache();
?>
图像页
<?php
//Directory NON-CACHED images are stored in
$dir = "i/";
//Array of files in the Directory
$files1 = scandir($dir);
//Used to limit results (100's of images)
$count = 0;
foreach ($files1 as $key) {
//If the file name is longer than 3 chars and the count is less
//than the amount of images I want displayed.
if (strlen($key) > 3 && $count <= 100){
$count++;
//dir2 is the directory/nameofFile.extension
//Eg: i/testImage.png
$dir2 = $dir.''.$key;
$info = new SplFileInfo($key);
//Image Cache variable
$cached_src = $imagecache->cache($dir2);
?>
<tr>
<td>
<!-- Link for light box for full resolution image -->
<a href="<?php echo $dir2;?>" data-popup="lightbox">
<!-- src of cached image is outputted and the alt is the name of the uncached image. -->
<img src="<?php echo $cached_src;?>" alt="<?php echo $key;?>" class="img-rounded img-preview">
</a>
</td>
<!-- More table stuff... -->
</tr>
<?php
} //End If
} //End for
?>
这应该通过简化$cached\u src
这应该可以通过简化在$cached_src
前面的斜杠来实现,我将看一下以供参考。如果缓存的映像还不存在,脚本将使用$\u服务器['HTTP\u主机]]
。因此,请验证其中的内容。如果您的$\u服务器['HTTP\u HOST']
没有以斜杠结尾,那么您的url就不会有斜杠。我会查看一下以供参考。如果缓存的映像还不存在,脚本将使用$\u服务器['HTTP\u主机]]
。因此,请验证其中的内容。如果您的$\u服务器['HTTP\u HOST']
没有以斜杠结尾,那么您的url就不会有斜杠。我猜$dir2是一个文件系统目录,这就是为什么您不能在其中添加斜杠。我猜$dir2是一个文件系统目录,这就是为什么不能在它上面加一个斜杠。这会把它放在一个根本不存在的根目录中。
<!-- Link for light box for full resolution image -->
<a href="<?php echo $dir2; ?>" data-popup="lightbox">
<!-- src of cached image is outputted and the alt is the name of the uncached image. -->
<img src="/<?php echo $cached_src; ?>" alt="<?php echo $key; ?>" class="img-rounded img-preview">
</a>