...

View Full Version : Path



alcool9999
10-17-2009, 04:21 PM
hi im trying to create and write to a file in a folder above where the php file is but it doesn't seem to work.

code:

$myFile4 = "players/" + $user + "test.txt";
$fh = fopen($myFile4, 'w');
fwrite($fh, "500");
fclose($fh);

i dont't see the problem

any help apreciated
thanks.

CFMaBiSmAd
10-17-2009, 04:34 PM
In php, + is a math operator. The php concatenation operator is a dot .

alcool9999
10-17-2009, 04:45 PM
yeh i just thought about that plus sign and changed it to this:

$myFile4 = $user;
$myFile4 .= "gold.txt";
$fh = fopen($myFile4, 'a+');
fwrite($fh, "500");
fclose($fh);

it works but obviously i haven't done the path.

would this work
$myFile4 = $user;
$myFile4 .= "gold.txt";
$path = "players/"
$path.=$myFile4;
$fh = fopen($path, 'a+');
fwrite($fh, "500");
fclose($fh);

Fou-Lu
10-17-2009, 05:59 PM
Not if you want to go above this file. To do that, you need to have .. in the filepath. Beware that PHP will work with a current working directory from the executing script, so if you include this into another file that is where it will execute from.


$path = dirname(__FILE__) . sprintf('/../%s/gold.txt', $user);
if (false !== ($fh = @fopen($path, 'a+')))
{
fwrite($fh, "500");
fclose($fh);
}

Hopefully you're not using this to track a user's 'gold'. This will start really taking up space on you're server. If you're using something dynamic you should consider the use of a database to take care of you're persistent storage.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum