Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
problem with fopen and fwrite
$name = $_POST['name'];
$content = $_POST['content'];
$url = $_POST['url'];
$ext = $_POST['ext'];
$fullurl = $url."".$ext;
$ourFileName = $fullurl;
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$myFile = $fullurl;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $content;
fwrite($fh, $stringData);
fclose($fh);
?>```
When ever the value of $content contains php the file contains the php in plaintext :( like echo (\"hello world\");
erm ....
Help me please!!
ty
Dotti.
or these errors
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\xampp\htdocs\functions\test.php on line 2
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\xampp\htdocs\functions\test.php on line 2
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\xampp\htdocs\functions\test.php on line 2
Parse error: syntax error, unexpected $end in C:\xampp\htdocs\functions\test.php on line 3
djdotti wrote:
$name = $_POST['name'];
$content = $_POST['content'];
$url = $_POST['url'];
$ext = $_POST['ext'];
$fullurl = $url."".$ext;
$ourFileName = $fullurl;
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$myFile = $fullurl;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $content;
fwrite($fh, $stringData);
fclose($fh);
?>```
When ever the value of $content contains php the file contains the php in plaintext :( like echo (\"hello world\");
erm ....
Help me please!!
ty
Dotti.
Couple things: disable the smilies so it's easier to read. Second, what are you trying to achieve? Because it seems that the file from which you're reading from is a variable so it will be difficult to help you without more information. You should probably also post the HTML form you're using :)
Secondly, it would probably be beneficial to use <?php instead of <? at the start of your code :)
newfile.htm :
<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<form method="POST" action="functions/newfile.php">
<p align="center">Filename :<br><input type="text" name="name" size="30"></p>
<p align="center">Url :<br><input type="text" name="url" size="30"><select size="1" name="ext">
<option value=".php">.php</option>
<option value=".htm">.htm</option>
<option>.html</option>
<option value=".txt">.txt</option>
</select></p>
<p align="center">Content :<br><textarea rows="10" name="content" cols="90"></textarea></p>
<p align="center"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>```
newfile.php :
```markup<?
$name = $_POST['name'];
$content = $_POST['content'];
$url = $_POST['url'];
$ext = $_POST['ext'];
$fullurl = $url."".$ext;
$ourFileName = $fullurl;
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$myFile = $fullurl;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $content;
fwrite($fh, $stringData);
fclose($fh);
?>```