I have a website where users can create new “topics.” Each topic has a folder (example: http://www.example.com/chemistry). I use mkdir() to create a new folder, but after it’s created how can i put files in the folder so that when someone goes to the chemistry folder there’s something to view? Since I haven’t found much information on how to do this im guessing there is a more popular way.
Share
What appears in the URL here is a URL. Repeat after me:
http://stackoverflow.com/questions/8774143/use-mdir-and-then-put-files-in-the-folderis a URL! It has a hostname, it has a path, it may have query parameters. It does not have “folders”!By default, in many web servers, a URL is mapped to a folder on the hard drive. But that’s just one way to do it. When visiting a URL, the web server just receives the request “give me whatever site there is at URL
http://stackoverflow.com/questions/8774143/use-mdir-and-then-put-files-in-the-folder“. The web server may choose to answer this by looking into a folder whose name matches the URL. Or it may simply invoke a program, give it the URL and deliver back whatever response the program happens to spit out.Try to learn about “URL rewriting” and “pretty URLs” and look into existing frameworks, since pretty much all frameworks implement this.