web_master Posted January 26, 2009 Share Posted January 26, 2009 Hi, how ca I load filenames and list them from folder which begin with nr-s example: in folder are files: 1_file.doc 1_file.xls 1_file.ai 3_file.pdf 4_file.ai how can I list only the files from folder wich begin with "1_" thnxs Quote Link to comment https://forums.phpfreaks.com/topic/142416-select-files-in-folder-which-begin-with-id-1/ Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 foreach (glob("1_*") as $file) { echo $file . " has a 1_ in it.<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/142416-select-files-in-folder-which-begin-with-id-1/#findComment-746163 Share on other sites More sharing options...
web_master Posted January 26, 2009 Author Share Posted January 26, 2009 foreach (glob("1_*") as $file) { echo $file . " has a 1_ in it.<br />"; } hm... Ill never use this... If the files are in dir: "advertise_files/" how can I list files which begin with 1_ from this directory Sorry, but I jus dont understand clearly how can I load the filenames and list them... Quote Link to comment https://forums.phpfreaks.com/topic/142416-select-files-in-folder-which-begin-with-id-1/#findComment-746171 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 ummm are you serious? <?php $fileListDir = "advertise_files/1_*"; $fileList = glob($fileListDir); echo "File list inside of " . $fileListDir . "<br />"; foreach ($fileList as $fileName) { echo $fileName . "<br />"; } ?> That will display those files exactly how you requested it in the first post. glob read up on glob to modify it to your needs. Quote Link to comment https://forums.phpfreaks.com/topic/142416-select-files-in-folder-which-begin-with-id-1/#findComment-746172 Share on other sites More sharing options...
web_master Posted January 26, 2009 Author Share Posted January 26, 2009 ummm are you serious? <?php $fileListDir = "advertise_files/1_*"; $fileList = glob($fileListDir); echo "File list inside of " . $fileListDir . "<br />"; foreach ($fileList as $fileName) { echo $fileName . "<br />"; } ?> That will display those files exactly how you requested it in the first post. glob read up on glob to modify it to your needs. File list inside of advertise_files/1_* only print this... everything is OK but no print anything ... no errors with: error_reporting(E_ALL); @ini_set('display_errors', '1'); Quote Link to comment https://forums.phpfreaks.com/topic/142416-select-files-in-folder-which-begin-with-id-1/#findComment-746182 Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 Well try some variations, read the glob manual. I have no clue where your script is located etc. <?php $fileListDir = "/advertise_files/1_*"; $fileList = glob($fileListDir); echo "File list inside of " . $fileListDir . "<br />"; foreach ($fileList as $fileName) { echo $fileName . "<br />"; } ?> That may work, or you may have to use other php items to get what you want like this: <?php $fileListDir = $_SERVER['DOCUMENT_ROOT'] . "/advertise_files/1_*"; $fileList = glob($fileListDir); echo "File list inside of " . $fileListDir . "<br />"; foreach ($fileList as $fileName) { echo $fileName . "<br />"; } ?> Or you may want to use relative paths. Come on and actually try some stuff for your self, who knows you may learn something by being adventurous. Quote Link to comment https://forums.phpfreaks.com/topic/142416-select-files-in-folder-which-begin-with-id-1/#findComment-746185 Share on other sites More sharing options...
web_master Posted January 26, 2009 Author Share Posted January 26, 2009 I look some a glob() manual... Maybe its My PHP is older or ... something like this because the script dont work... Quote Link to comment https://forums.phpfreaks.com/topic/142416-select-files-in-folder-which-begin-with-id-1/#findComment-746191 Share on other sites More sharing options...
Dragosvr92 Posted July 5, 2010 Share Posted July 5, 2010 ummm are you serious? <?php $fileListDir = "advertise_files/1_*"; $fileList = glob($fileListDir); echo "File list inside of " . $fileListDir . "<br />"; foreach ($fileList as $fileName) { echo $fileName . "<br />"; } ?> That will display those files exactly how you requested it in the first post. glob read up on glob to modify it to your needs. The Script works fine for me thanks i wanted to know how to do this some time ago btw Sorry for bumping the Topic ... Quote Link to comment https://forums.phpfreaks.com/topic/142416-select-files-in-folder-which-begin-with-id-1/#findComment-1081146 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.