Jump to content

How to fopen() into a specific directory???


galvin

Recommended Posts

I have fopen() code that works fine..

 

 

						$filename = "trade.php";$filehandle = fopen($filename, 'w') or die("can't open file");fclose($filehandle);

 

 

But I want it to create the file "trade.php" in a specific directory called "tradepages".

 

I tried changing the one line to be...

 

 

$filename = ".../tradepages/trade.php";

 

 

 

But that just gives an error saying no such directory exists (even though it definitely does).

 

There has to be a way to create files in whatever folder/directory you want, right?

 

Anyone know how, or what I'm doing wrong?

 

 

Link to comment
https://forums.phpfreaks.com/topic/214120-how-to-fopen-into-a-specific-directory/
Share on other sites

Try this:

 

 

$filename = $_SERVER['DOCUMENT_ROOT']."/tradepages/trade.php";$filehandle = fopen($filename, 'w') or die("can't open file");fclose($filehandle);

 

 

This is assuming that /tradepages is right off the root of the server if not you will have to adjust.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.