Forum Moderators: coopster

Message Too Old, No Replies

including in fwrite()

         

jman11

1:34 am on Oct 30, 2009 (gmt 0)

10+ Year Member



i have a page where i upload a .php file to server, and i extract the contents, and re-write them with fwrite(). the contents im overwriting it with though isnt showing up as planned, im using include() function multiple times like this, and only the include("inc/footer.php") is showing up on the page.


$contents = file_get_contents($_FILES["file"]["tmp_name"]);
$open = fopen($_FILES["file"]["tmp_name"],"a+");
$write = fwrite($open,include("inc/up/att.php").include("inc/up/header.php").$contents.include("inc/right.php").include("inc/footer.php"));
move_uploaded_file($_FILES["file"]["tmp_name"],
$category.'/' . $filename);

any ideas how to get the other includes to work?

i just realized maybe i could use file_put_contents as well but that is not working either.

TheMadScientist

3:33 am on Nov 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How about:

ob_start();
include ("inc/up/att.php");
$att = ob_get_contents();
ob_end_clean();

ob_start();
include ("inc/up/header.php");
$header = ob_get_contents();
ob_end_clean();

ob_start();
include ("inc/right.php");
$right = ob_get_contents();
ob_end_clean();

ob_start();
include ("inc/footer.php");
$footer = ob_get_contents();
ob_end_clean();

$contents = file_get_contents($_FILES["file"]["tmp_name"]);
$open = fopen($_FILES["file"]["tmp_name"],"a+");
$assembled=$att.$header.$contents.$right.$footer;
$write = fwrite($open,$assembled);
move_uploaded_file($_FILES["file"]["tmp_name"],
$category.'/' . $filename);

/* Also, I'm not seeing anything to execute $write, so you might need to switch the line to: fwrite($open,$assembled); (remove the variable storage) */

jman11

5:50 am on Nov 4, 2009 (gmt 0)

10+ Year Member



oh i got it, i just did file_get_contents, then create a new php file, then just include them in there, and the extracted contents were pasted in. all in one quote without seperation.

TheMadScientist

5:56 am on Nov 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Cool. Good to know how you handled it...

I don't deal with file writing too often, but will need to shortly (I think) so it's good to know what other people do.