Create a file and save it to a parent directory using PHP? -


How do I create a file and save it to a root directory?

That's because you can see that from my script below, the PHP "referer.log" saves the file in the same directory where it is PHP, but I want to save it to a root directory?

This is my current PHP:

  & lt ;? Php $ fname = "referer.log"; $ File = fopen ($ fname, 'a +'); $ Url = "$ _SERVER [REQUEST_URI]"; Filitt ($ file, "referrer: $ url"); Fclose ($ file); ? & Gt;  

Say my current directory

/ forums / link / contact /

I should have it

/ forum / link / log /

Thanks everyone.

You are free to use relative paths:

  $ Fname = "../logs/referer.log";  

I recommend you to check that the directory exists and will create it if it is not:

  if (! Is_dir ('. ./logs')) {mkdir ('.. / logs', 0750, true); }  

Hope it helps.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -