alexandervj Posted May 15, 2015 Share Posted May 15, 2015 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 https://forums.phpfreaks.com/topic/296347-having-trouble-with-scandir-getting-the-right-file-path/ Share on other sites More sharing options...
alexandervj Posted May 15, 2015 Author Share Posted May 15, 2015 nevermind i figured it out Link to comment https://forums.phpfreaks.com/topic/296347-having-trouble-with-scandir-getting-the-right-file-path/#findComment-1512004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.