Reputation: 4041
I have a website where users can create new "topics." Each topic has a folder (example: 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.
Upvotes: 0
Views: 2399
Reputation: 522024
is SO useing a CMS? becasue when i asked this question a "folder" appeared in the URL with my question ID.
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-folder
is 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.
Upvotes: 1
Reputation: 2908
you can copy files:
copy($source, $desitination);
Upload files: see move_uploaded_file
Write files: see fwrite
PS. Just check if the folder exists first, eg if (file_exists($dir))
before calling mkdir($dir) or you will get warnings, or suppress mkdir() like this @mkdir() to silence any warnings
Upvotes: 1
Reputation: 1853
use copy function
copy($source, $dest);
I don't know if this is what you meant
Upvotes: 0
Reputation: 4855
Look at that : http://php.net/manual/en/function.chdir.php By changing your directory you could display the content of the folder to your user.
Upvotes: 0