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

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -