I am trying to use the scandir() function in PHP to get a list of files in a directory. However, it’s not working. Is it perhaps blocked? I could see that being true because then it might be possible to get a list of files in someone else’s account since this is a shared server.
Here is the code I’m using. I have tried several different directories, even starting from /home/vol3_4/epizy.com/epiz_########/htdocs. I’ve also tried different methods for printing the list, namely print_r, echo, and print. When I set the directory to /tmp (which I’m not sure what that is), it does give me a list, but it doesn’t work for any other directory. Is there an issue with my understanding of the code or is this a server limitation?
I just tried it and couldn’t get it to work. It just produced a 500 error when I went to that page. I couldn’t even get the directory “/tmp” to work, which previously worked with my code. What directory are you using? Can I simply use /htdocs or do I need to do /home/vol3_4/epizy.com/epiz_########/htdocs?
When you do this, it looks for a folder called DIRECTORY at the root folder of the entire server, not your hosting account. For security, your PHP scripts can’t access files outside of their website directories. We don’t want people poking around the server setting or other people’s websites, after all.
If you want to find the files in the folder DIRECTORY in your own website, you could do ./DIRECTORY to list the folder relative to the current directory.