Jump to content

Helping adding text to .txt file


Jnerocorp

Recommended Posts

Hello,

 

For some reason this code is not working for me it is creating that file and I can save it but there is nothing in the .txt file

 

here is my code:

 

<html>
<head>
<title>Form & Form Output</title>
</head>
<body>
<center>
<h1> Generate </h1><br>
<?php
if(isset($_POST['submit'])) {

$imgurl = $_POST['imgurl'];
$filename = rand();
$fullurl = "<img src='$imgurl'>";

$myFile = "$filename.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "$fullurl";
fwrite($fh, $stringData);
fclose($fh);




echo $fullurl
?>
<br><br>
<textarea cols="50" rows="10"><img src="<?php echo $imgurl ?>"></textarea><br>
Right Click <a href='./<?php echo "$filename.txt"; ?>'>Here</a> and Click "Save as".

<?php
} else {
?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method=POST>
<p>This will generate an image code to put on your website.</p>
<table>
<tr>
<td>Direct link:</td><td><input type=text name="imgurl" size="100"></td>
<tr>
<td><input type=submit name="submit" value="GET CODE!"></p></td>
</tr>
</table>
</form>

<?php
}
?>


</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/177282-helping-adding-text-to-txt-file/
Share on other sites

hmm, I don' see anything particularly wrong with this code. are you sure your filename is right, and that you are opening the right file name? try to echo out the variable. remember, since you have the open mode to 'w', it will overwrite anything that was previously there before. you can append information with 'a'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.