Search code examples
phpfwrite

PHP Process Won't Overwrite With Fwrite


I have a problem. I've tried this with localhost on my PC and I have checked every single possibility that I can think of, but the problem still exists. So here it is:

When I click on a link "Equip" it links to a .php file.

In that file, it says:

<?

$user = username
$character = charactername

$itemtxt = "http://www.intooblivion.neq3.com/$user/$character/stats/inventory/armoury/".$item."_equipped.txt";
$itemfh = fopen($itemtxt, "w");
fwrite($itemfh, "i");
fclose($itemfh);

?>

The problem is, it's not actually doing it. I'm checking the file after the process has been done and it's not actually doing as it's told. It's leaving all of the files that I ask it to modify untouched and I'm not sure why.

Edit: If I try to use the whole path with $_SERVER['DOCUMENT_ROOT'] is just gives me this error:

fopen(/home/u542847060/public_html/StealthParanoia/Aetyr/stats/inventory/armoury/ironsword_equipped.txt): failed to open stream: No such file or directory

That's silly, because that's the exact directory of the file.

FIXED: I was derping incredibly hard. My friend (Haden693) helped me to realise that because the ".txt" was in the same place as the ".php" I didn't need to specify the path in the first place. Whoops.

Thanks for all your help, guys, love you.

<3


Solution

  • <?
    
    $user = username
    $character = charactername
    
    $itemtxt = $item."_equipped.txt";
    $itemfh = fopen($itemtxt, "w");
    fwrite($itemfh, "i");
    fclose($itemfh);
    
    ?>