• Welcome to Valhalla Legends Archive.
 

Ekk.. fopen/fwrite problem

Started by ChroniX, April 14, 2008, 06:49 PM

Previous topic - Next topic

ChroniX

Well, to start things out, here is my code being used:

<?php

$file 
fopen("/mps/projects/project_" $_POST['projectnumber'] .".php""w");

echo 
fwrite($file" * deleted whats to be written since it's not needed right now, and to save space * ");

fclose($file);

?>



The problem I'm having is that the rest of the script up until this point runs fine, but when it's suppose to execute the fopen/fwrite functions it doesn't do so. Also, just to experiment, I went to fopen("/mps/projects/project_" . $_POST... etc. and changed the fopen url to the root directory... looking something like this: fopen("test.php", "w"); echo fwrite($file, " * content * ");... pretty much just taking away all the subdirectories so that the file is created/written to in the base directory, and it works just as i want it to when I take away the extra folders (/mps/projects/). Does anyone see something I've done wrong? I'm still new with PHP but I'm sure it's not a syntax error since all I'm doing is taking away those two directories and it works just fine... I could be wrong.

Any and all help/suggestions are very much appreciated!

FrostWraith

Well, it seems that if it wasn't functioning at all, there might be some errors posted.

Do you have error messages enabled?

Also, as a programming suggestion, after you open a file, it is good practice to check if it was opened successfully.
<?php

$file 
fopen("/mps/projects/project_" $_POST['projectnumber'] .".php""w");

if (
$file)
{
      echo 
fwrite($file" * deleted whats to be written since it's not needed right now, and to save space * ");
}

fclose($file);

?>


If your code doesn't step through that if statement, there was an error opening the file, and not with anything after.

Barabajagal

Are you sure your root directory is where you think it is?

ChroniX

Ah, fixed that problem.

Now, I have another question, and instead of making yet another thread, I'll just post it in this one.

Can you store global variables in variables, like so:

<?php

$var = echo $_SERVER['PHP_SELF']

?>

Barabajagal

Uh, just $var = $_SERVER['PHP_SELF'];

ChroniX

I'm not saying your wrong, but I should have stated my intentions before hand. I wanted to do something like this with it.

<?php

$var = echo $_SERVER['PHP_SELF'];

?>

<form action="<?php $var; ?>" method="post">

...etc.

Orrrr... I see, you were right. I would have to echo the variable anyhow =/ sorry lol