Directory Helper Question - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Directory Helper Question (/showthread.php?tid=64294) |
Directory Helper Question - wolfgang1983 - 02-04-2016 I am using the codeIgniter directory helper but have small question. When I display my images and directory's in my foreach loop $image variable is a directory it throws error. Error Message: Array to string conversion I have attached image of error. PHP Code: array (size=5) As shown in var dump sub folder is directory but when I echo out the foreach loop it throws error for that directory. Any suggestion I need to display sub directory and images. Images I can display fine PHP Code: <?php View PHP Code: <div class="container" style="margin-top: 20px;"> RE: Directory Helper Question - InsiteFX - 02-04-2016 Try casting $image ie; (string) $image etc; RE: Directory Helper Question - keulu - 02-04-2016 that's because 'subfolder' key is not a string but an array. remove the key 'subfolder' with the unset() method from your array and everything is gonna be ok unset($images['subfolder']); RE: Directory Helper Question - keulu - 02-04-2016 but if you have images in your subfolder, you can use a recursive method. a recursive methods is a method who call itself PHP Code: $images_directory = directory_map('./images/catalog/', FALSE, TRUE); i'm not sure this methods work like that. i writted it from scratch. but this is how to do a recursive method. RE: Directory Helper Question - wolfgang1983 - 02-04-2016 (02-04-2016, 09:42 AM)keulu Wrote: but if you have images in your subfolder, you can use a recursive method. I am just a bit confused will that let me still display the folders as well as images and there file names? RE: Directory Helper Question - wolfgang1983 - 02-04-2016 (02-04-2016, 03:34 AM)InsiteFX Wrote: Try casting $image ie; (string) $image etc; Seem to have it working now by using scandir and array_diff PHP Code: <?php |