PDA

View Full Version : [Help] Using Php To Write Php To A File!



Decode
10-03-2008, 06:55 PM
Ive got a problem, i have made a code to write some data to a .php file, but when it writes to the file, the data.php file only contains '<? ?>' in it. This is the part of the code that writes to the file.


$write2file = fopen("data.php", "w");
fwrite($write2file,"<?php");
fwrite($write2file,"echo \"$Data\";");
fwrite($write2file,"?>;");
fclose($write2file);
echo "Done!";

Flisker
10-03-2008, 07:01 PM
did you put <?php CODE ?> in ?

Blob
10-03-2008, 07:02 PM
Ive got a problem, i have made a code to write some data to a .php file, but when it writes to the file, the data.php file only contains '<? ?>' in it. This is the part of the code that writes to the file.


$write2file = fopen("data.php", "w");
fwrite($write2file,"<?php");
fwrite($write2file,"echo \"$Data\";");
fwrite($write2file,"?>;");
fclose($write2file);
echo "Done!";




<?php
$text = <<<HTML
<?php
echo "{$data}";
?>
HTML;
$file = fopen("data.php", "w");
fwrite($file, $text);
fclose($file);
echo "Done!";
?>

Navicat
11-03-2008, 12:23 AM
What is with the whole <<<HTML thing?

Never seen that before.

Just make it



<?php
if ($_GET ["action"] == "update") {
$stuff = $_POST ["stuff"];
$filename = $_POST ["filename"];
$file = @fopen ( $filename . ".php", "w+" );
@fwrite ( $file, $stuff );
@fclose ( $file );
echo "Done";
exit ();
}
?>
<form name="thing" action="?action=update" method="post">
Filename (exclude .php): <br />
<input type="text" name="filename"><br /><br />

Contents:<br />
<textarea name="stuff"></textarea>
</form>


Should do it.

Protege
11-03-2008, 06:40 AM
What ever your trying to do, it looks horrible - Explain further and I might be able to help.

Blob
11-03-2008, 04:22 PM
What is with the whole <<<HTML thing?

Never seen that before.

Just make it



<?php
if ($_GET ["action"] == "update") {
$stuff = $_POST ["stuff"];
$filename = $_POST ["filename"];
$file = @fopen ( $filename . ".php", "w+" );
@fwrite ( $file, $stuff );
@fclose ( $file );
echo "Done";
exit ();
}
?>
<form name="thing" action="?action=update" method="post">
Filename (exclude .php): <br />
<input type="text" name="filename"><br /><br />

Contents:<br />
<textarea name="stuff"></textarea>
</form>


Should do it.

Basically, if you want to do a load of HTML with ' and "'s and cba to do \, you just use
$string = <<<HTML
HTML
"
/
'
alaldkasd
HTML; // MUST HAVE NO INDENTS;
echo $string;

Navicat
11-03-2008, 04:42 PM
What ever your trying to do, it looks horrible - Explain further and I might be able to help.

What does, my code?


Basically, if you want to do a load of HTML with ' and "'s and cba to do \, you just use
$string = <<<HTML
HTML
"
/
'
alaldkasd
HTML; // MUST HAVE NO INDENTS;
echo $string;

Oh, never done that before. I just use the opposite ' or " of what is used more.

Decode
11-03-2008, 04:47 PM
What ever your trying to do, it looks horrible - Explain further and I might be able to help.
Well there is a page called submit.php, there is a form on that page, and it has a textbox with the name data and a submit button.

When you click submit i need it to write this code to a .php file

<?php
echo "$Data"
?>

:)

Protege
11-03-2008, 05:31 PM
I did some code to write to a file, http://www.habboxforum.com/showthread.php?t=463370 - that should give you an outline.

Want to hide these adverts? Register an account for free!