Вопрос

On /portfolio.php (which is located on root of the site) I want to show all images from the directory /trabajos/tataviajes.

foreach(scandir('./trabajos/tataviajes/', 1) as $filename){
     echo '<img src="'.$filename.'"/>';
 }

The function open the images like this: /portfolio/123.jpg instead of /trabajos/tataviajes/123.jpg

The htaccess code that I think it might interfere is:

RewriteRule ^portfolio/(\w+)/?$ portfolio.php?i=$1

Was I clear? What is the issue?

Thanks in advance!

Это было полезно?

Решение

scandir returns an array of filenames not file paths see http://php.net/scandir#refsect1-function.scandir-returnvalues

You need to prefix the path to the filename. Consider something like:

$directory = 'trabajos/tataviajes/';
foreach(scandir($directory, 1) as $filename){
    echo '<img src="/'.$directory.$filename.'"/>';
}

also, consider using htmlentities so special characters in the path will not mess up your markup:

echo '<img src="'.htmlentities('/'.$directory.$filename).'"/>';
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top