Jump to content

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


alexandervj
Go to solution Solved by 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';
    }
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.