writing to a directory

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
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

writing to a directory

Post by corillo181 »

why this doesn't work?

Code: Select all

<?php
$do=fopen("sing/index.php",'r');
$write='this is all it man';
if($do){
fwrite($do, $write);

}
fclose($do);
?>
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

Post by corillo181 »

oh ok i had to use fopen'w' not 'r', but what if i want to throw a whole page full of code do i have to attach it to a variable too ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can write it directly.

Code: Select all

fwrite($foo, 'bar');
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

Post by corillo181 »

yeah but i mean if i got a whole page i want to dumb into another page.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Same solution.
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

Post by corillo181 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


why this dont work then?

Code: Select all

<?php
$do=fopen("sing/index.php",'w');
$write=fopen("htmlforms/join_form.html",'r');



if($do){
fwrite($do, $write);

}
fclose($do);
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$write isn't a string, it's a resource. You need to use fread() or file_get_contents()

However if you intent is to copy the file, then copy() works far better.
corillo181
Forum Commoner
Posts: 76
Joined: Wed Apr 26, 2006 3:02 pm

Post by corillo181 »

thank you feyd
Post Reply