Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create php file using php 1

Status
Not open for further replies.

davejam

Technical User
Jan 6, 2004
313
GB
hi all,

i am trying to create a system that takes me somewhat out of the loop so i can concentrate on other thing.

i have written a basic template website for them to use, but i want them to be able to change the basic setup via a webpage....

i have a config file that has all of the connection details, default colours, default text for the site.

i want to be able to allow an admin to create / modify this for a site but am having trouble 1.creating without having to keep modifying permissions (leaving myself a bit open) 2.getting php code into the file.

currently i've been playing with it and had to allow permission to write for all users (not surs is the right way to do it)

but anyway, to the code.

i'm using the method

$fp = fopen("your_new_file.txt", "w");
fwrite($fp, $myBuildVar);
fclose($fp);

where $myBuildVar is the text string i've put together for the file.

The file needs to contain set variables so i can use them throughout the site.... for example i'm trying to create it with the following code


# site background
$myBuildVar = "$confBgCol = '#111111';";
$myBuildVar = $myBuildVar."$confFrCol = '#000000';";

but i get the created file as

= '#111111'; ='#000000';

any ideas on a way to do this??

thankyou, any advice, hints or tips would be greatly appreciated

daveJam

*two wrongs don't make a right..... but three lefts do!!!!*
 
davejam,
Your variable $confBgCol is getting interpolated since its in double quotes.Try using single quote around the whole string.
Change
Code:
$myBuildVar = "$confBgCol = '#111111';";
$myBuildVar = $myBuildVar."$confFrCol = '#000000';";
to
Code:
$myBuildVar = '$confBgCol = "#111111";';
$myBuildVar = $myBuildVar.'$confFrCol = "#000000";';



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
oooh, so far thats brilliant...

$confBgCol="#111111";$confFrCol="000000";

so thats perfect, just wondering for ease when someone else is looking can i get that to put line breaks in, can never remember if i use /n/r or try and find the ascii character...

think i would rather overwrite the file each time rather than add to it, is there a way to delete the contents and start again each time, or would i need to put a delete file in???

thanks, can't believe these ' and " are still giving me hastle!!!



daveJam

*two wrongs don't make a right..... but three lefts do!!!!*
 
davejam,
Do you want to write the file all over again for each call to script?
If yes, then opening a file in write mode (the way oyou are opening) does exactly that, so you don't need to delete the content from file.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
thats brilliant then... cheers, should have really checked that first.

is there a better way to change the permissions... without opening myself up too much??

daveJam

*two wrongs don't make a right..... but three lefts do!!!!*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top