I want to know how to get the folder in wordpress and get all the files from that folder in an array so i can use it as anchor tag to download it .. I'm trying to search on google but because i'm new so no luck for me today will any of you please help me? also want to save it if any new files i add then it have to automatically come to that place as new anchor any one can help me please? and also want to display them on wordpress admin dashboard
Asked
Active
Viewed 1,701 times
0
-
Look into PHP's `glob()` function. – disinfor Apr 19 '18 at 14:07
-
what if i want to give a folder path into this function? – Huzail Jamil Apr 19 '18 at 14:24
-
Right now, you don't have a WordPress problem, but PHP. The list of duplicates should be enough for you to write your code and apply wherever you're using it on WP. – brasofilo Apr 19 '18 at 14:38
-
Thanks to you about this – Huzail Jamil Apr 19 '18 at 16:33
1 Answers
2
If you know the name of the directory, you could check PHP scandir()
Something like:
$directory = "/folder-name/";
$directory_array = scandir($directory);
print_r($directory_array);
This should return an indexed array containing images names.
Keep in mind that WordPress does not archive all files in a single folder, by default they are organized by year and month.

FrancescoCarlucci
- 1,570
- 12
- 13
-
Thanks i'll keep in my mind actually i'm saving pdf in a folder and trying to fetch them in wordpress dashboard so admin can click on it to download so that's why i need this – Huzail Jamil Apr 19 '18 at 14:25
-
it should work in wp-admin. You will need to attach the path of the file to filename returned from scandir(). Good luck! – FrancescoCarlucci Apr 19 '18 at 14:32
-