我有一个非常奇怪的错误!
这是我的代码:
if (file_exists($this->template->large_image_location)) {
$tmp_src = imagecreatefromjpeg($this->template->large_image_location);
//work with $tmp_src
} else {
//no picture there
}
我无法重现该错误,但某些用户说他们收到以下错误消息:
错误异常 [警告]:
imagecreatefromjpg(/srv/.../.../.../th_vorschau_123.jpg): 无法打开流: 没有这样的文件或目录!
为什么我甚至会收到此错误?我在尝试加载图像之前用file_exists
证明文件!
格拉维奇是对的。但有时realpath()
会导致问题。因此,请使用此功能。[已测试]
<?php
function truepath($path){
// whether $path is unix or not
$unipath=strlen($path)==0 || $path{0}!='/';
// attempts to detect if path is relative in which case, add cwd
if(strpos($path,':')===false && $unipath)
$path=getcwd().DIRECTORY_SEPARATOR.$path;
// resolve path parts (single dot, double dot and double delimiters)
$path = str_replace(array('/', '\'), DIRECTORY_SEPARATOR, $path);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
$absolutes = array();
foreach ($parts as $part) {
if ('.' == $part) continue;
if ('..' == $part) {
array_pop($absolutes);
} else {
$absolutes[] = $part;
}
}
$path=implode(DIRECTORY_SEPARATOR, $absolutes);
// resolve any symlinks
if(file_exists($path) && linkinfo($path)>0)$path=readlink($path);
// put initial separator that could have been lost
$path=!$unipath ? '/'.$path : $path;
return $path;
}
if (truepath('redarrowdown.gif')){
$tmp_src = imagecreatefromjpeg(truepath('redarrowdown.gif'));
//work with $tmp_src
echo "success";
}
else
{
echo "fails";
//no picture there
}