문제

Im using glob() to find any image files matching a rule.

I'm using the following code:

$photo = glob(($_SERVER['DOCUMENT_ROOT'] .'/stocklist/photo/'.$row['Scientific'].'*.jpg'));

print_r(glob(($_SERVER['DOCUMENT_ROOT'] .'/stocklist/photo/'.$row['Scientific'].'*.jpg')));

Which produces the following:

    Array ( [0] => /var/www/web/stocklist/photo/Pituophis deppei jani.jpg 
[1] => /var/www/web/stocklist/photo/Pituophis deppei jani1.jpg )

Then when i echo the images to the page using the code below, it displays 2 broken image icons...

$length = count($photo);


        if($length) {
        echo"<ul id='slide'>";
        for ($i = 0; $i < $length; $i++) {
        echo "<li><img src='".$photo[$i]."' alt='".$row['Name']."'></li>";}

        echo "</ul><ul id='slide-pager'>";

        for($i2 = 1; $i2 < $length+1; $i2++) {
        echo "<li><a href='#".$i2."'>".$i2."</a></li>";

        }
        echo "</ul>";
        }
        else {
        echo "<img src='/stocklist/photo/placeholder.jpg' class='img-right'><br clear='right'>";
        }
도움이 되었습니까?

해결책

Try changing to:

$photo = (glob('stocklist/photo/'.$row['Scientific'].'*.jpg'));
print_r(glob('stocklist/photo/'.$row['Scientific'].'*.jpg'));

That way your returned paths will already be relative to your public folder. You could also do a str_replace as @sergiu suggested, but why not just get rid of it entirely?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top