Dru
Dru

Reputation: 556

PhP fopen creates file with Path name

Trying to update a file file.xml, which is with folders dirA/dirB/dirC/file.xml where dirA is the current working dir. The file file.xml exists and has write permissions.

Using the following code works in local but on server it created a file by name "dirA\dirB\dirC\file.xml" outside dirA and saves into it

$file = fopen("dirA\dirB\dirC\file.xml", "w+")
fputs($file, $xmlFile);
fclose($file);

Any idea why?

Upvotes: 0

Views: 54

Answers (1)

Nilse
Nilse

Reputation: 140

Maybe because you are running another environment on your server? Windows and Linux are a little bit itchy on their folders.

You may also check if you have to use backslashes or not!

Probably you also have to quote them:

$file = fopen("dirA\/dirB\/dirC\/file.xml", "w+");

Upvotes: 1

Related Questions