Valhalla Legends Forums Archive | Web Development | Ekk.. fopen/fwrite problem

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

[code]<?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);

?>[/code]


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!
April 14, 2008, 11:49 PM
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.
[code]<?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);

?>[/code]

If your code doesn't step through that if statement, there was an error opening the file, and not with anything after.
April 16, 2008, 12:53 AM
Barabajagal
Are you sure your root directory is where you think it is?
April 16, 2008, 1:14 AM
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']

?>
April 16, 2008, 10:21 PM
Barabajagal
Uh, just $var = $_SERVER['PHP_SELF'];
April 17, 2008, 12:02 AM
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
April 17, 2008, 10:59 PM

Search