[SOLVED] fopen help needed please.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MWG_T_H_O_M_A_S
Forum Newbie
Posts: 7
Joined: Mon Jun 28, 2004 10:33 am

fopen help needed please.

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

where are you getting $adress from?
MWG_T_H_O_M_A_S
Forum Newbie
Posts: 7
Joined: Mon Jun 28, 2004 10:33 am

Post 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 :P.

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
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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.
MWG_T_H_O_M_A_S
Forum Newbie
Posts: 7
Joined: Mon Jun 28, 2004 10:33 am

Post 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
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Have a look at fopen().

You are using...

Code: Select all

$fp =fopen($adress , "w+", 1);
You could try...

Code: Select all

$fp =fopen($adress , "w+");
Where $adress would be the full path to the file.
MWG_T_H_O_M_A_S
Forum Newbie
Posts: 7
Joined: Mon Jun 28, 2004 10:33 am

Post by MWG_T_H_O_M_A_S »

thanx man, you have been so helpfull, it works!!!!! and its great :D

my first project is a success! thanx!!!

Tom
Post Reply