Page 1 of 1
fopen help needed please.
Posted: Mon Jun 28, 2004 10:33 am
by MWG_T_H_O_M_A_S
hi
on my webpage i am having great problems using the fopen command to create a new page.
i am using
"$fp =fopen($adress , "w+", 1);" with $adress being the name of the page i want to be created (it includes .html at the end) .
On my computer and personal webserver this works fine, and will create new pages, however on my webhost no new page will be created. If i create and upload a blank page with $adress as the name, the script will write to the page, so the problem is definitely that it is not creating the file for some reason.
I have chmodded the directory to 777, is there anything else i can do?
Thanx, if u need any more info pls ask. i really need some help
Tom
Posted: Mon Jun 28, 2004 10:42 am
by John Cartwright
where are you getting $adress from?
Posted: Mon Jun 28, 2004 10:52 am
by MWG_T_H_O_M_A_S
ok, all the variables work and are generated from a form on the other page.
Basicalyl the code i have is.
Code: Select all
$name2 = str_replace (" ", "_",$name);
$manufacturer2 = str_replace (" ", "_",$manufacturer);
$model2 = str_replace (" ", "_",$model);
$adress = $manufacturer2.$model2.$name2.".html" ;
echo "Form Varied. Thankyou for submitting us your car.<br><br> ";
echo "Your car has been uploaded to <a href=".$adress."> HERE </a><br>";
//<a href=".$DOCUMENT_ROOT."/tom/".$manufacturer2.$model2.$name2.".html> HERE </a><br>";
//$adress = $manufacturer2.$model2.$name2.".html" ;
echo $adress ;
$fp =fopen($adress , "w+", 1);
//$fp =fopen("$DOCUMENT_ROOT/tom/".$manufacturer2.$model2.$name2.".html", "w", 1);
if (!$fp)
{
echo "<p><strong> Your order could not be processed at this time."
."Please try again later.</strong></p></body></html>" ;
exit;
}
fwrite($fp, $outputstring);
fclose ($fp);
?>
$output string is tons of html and variables all put into 1 styring, it works and i think is too long to put here

.
Basically all the variables and stuff work, eg i can echo $adress and get what i want to come out, the problem is that the fopen command does not create a page, it will only write to one i have alrdy made ( which is not what i want, fopen must create the page depeniding on what the varialbe $adress is).
Thanx again
Tom
Posted: Mon Jun 28, 2004 11:18 am
by redmonkey
I'm not sure but, perhaps as you are using the 'search include path' switch PHP does not know where to create this file if it doesn't already exist. It may even be creating it in the directory it is running in if the file does not exist previously. As I said, I'm not entirely sure but you could try specifying the full path to the file and dropping the 'search include path' switch.
Posted: Mon Jun 28, 2004 11:23 am
by MWG_T_H_O_M_A_S
what exactly do you mean by "dropping the 'search include path' switch."
This is my first php project and i am yet to come across this term :X
Thanx,
Tom
Posted: Mon Jun 28, 2004 11:28 am
by redmonkey
Have a look at
fopen().
You are using...
You could try...
Where $adress would be the full path to the file.
Posted: Tue Jun 29, 2004 1:00 pm
by MWG_T_H_O_M_A_S
thanx man, you have been so helpfull, it works!!!!! and its great
my first project is a success! thanx!!!
Tom