Home > Software design >  access all images oustside documentRoot not workng Apache windows
access all images oustside documentRoot not workng Apache windows

Time:10-31

when a User upload Images, I have a folder outside my documentRoot which save it. I have tried to loop through all the images and show them but it is not working. php apache alias. I have not hosted the website yet.

alias conf

 Options Indexes FollowSymLinks Includes ExecCGI
 AllowOverride All
 Require all granted
</Directory>
Alias /webdev "c:\exclusive\webdev"

testing it within my documentRoot php my document root location C:\xampp\htdocs\create The alias root location C:\exclusive\webdev

$path = '/webdev';
    $ImgDir = webdev/;
     $files = new FilesystemIterator($path);
     $images = new RegexIterator($files, '/\.(?:jpg|png|gif|webp)$/i');
     foreach ($images as $image) { 
        
        $fie =$image->getFilename();
        echo '<img src="',$ImgDir, $fie,'" width="300"/>';
}

CodePudding user response:

Without testing you can probably use the absolute path to the source files and then the alias to display the images.

$path = 'c:\\exclusive\\webdev';
$ImgDir = '/webdev';

$files = new FilesystemIterator( $path );
$images = new RegexIterator( $files, '/\.(?:jpg|png|gif|webp)$/i' );

foreach( $images as $image ) {
    printf( '<img src="%s/%s" width="300"/>', $ImgDir, $image->getFilename() );
}
  • Related