Jump to content

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'

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.