Jump to content

having trouble with scandir() / getting the right file path


alexandervj

Recommended Posts

Hello,

 

I'm trying to get all the files in a certain directory and display them as links. My code below scans the directory successfully and displays the titles of all the files, but the path to the files must be wrong or something because when you click on the links nothing comes up and the image displayed as a preview is a broken image. I'm not sure whats wrong with my code, any help would be appreciated. Thanks

<?php
    if(is_dir('./uploads/LotID '.$this->uri->segment(3).'/RunID '.$this->uri->segment(4).'/PartID '.$this->uri->segment(5).'/Attachments')){
        $dir = './uploads/LotID '.$this->uri->segment(3).'/RunID '.$this->uri->segment(4).'/PartID '.$this->uri->segment(5).'/Attachments';
        $files = scandir($dir);
        if($files){
            foreach($files as $f => $file){
                if ($file === '.'){
                    
                } else if ($file === '..'){
                    
                } else {
                    echo '<a href="'.$dir.'/'.$file.'" title="'.$file.'" data-gallery>';
                    echo '<img src="'.$dir.'/'.$file.'" alt="'.$file.'"><br />';
                }
                
            }
        }
    } else {
        echo 'No attachments uploaded yet';
    }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.