Jump to content

revise a text file


dbrimlow

Recommended Posts

After a long PHP layoff, I need to get back and start from scratch.

 

I have a text file with hundreds of emails (2500 actually).

I need to create a management form for the client to search and remove email when requested they be removed from the list.

 

I could go Database, but I wanted to do this first. But it is not working. This should be elementary for most of you I'm sure.

 

I think the problem has something to do with calling the form action. It doesn't write the txt file on submit

 

<!-- sets the action for submit -->
<?php
if(isset($_POST['SaveEmail']))
{
    $open = fopen("testFile.txt","w+");
    $text = $_POST['EditList'];
    fwrite($open, $text);
    fclose($open);
    echo "email list updated.";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>test create a file</title>
</head>
<body>

<!-- opens the text file in a form text area -->

<form  method="post" enctype="text/plain">
  <textarea id="FormsMultiLine3" name="EditList" rows="200" cols="79" style="width: 645px; white-space: pre;">

<?php
    $filename = "testFile.txt";
    $fh = fopen($filename, "r+");
    $data = fread($fh, filesize($filename));
    fclose($fh);
    echo $data;
?>
  </textarea>
  <input type="submit" id="Button1" name="SaveEmail" value="SaveEmail" style="height: 24px; width: 57px;">
  </form>


</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/144992-revise-a-text-file/
Share on other sites

what is going wrong? what does the form submission do? empty the file?

 

Whoa, sorry. I asked this question like a noob to posting!

 

I have an email distribution list in a text file - call it testFile.txt - that simply lists 2500 emails. We use it to send html email flyers about apartments available.

 

In the flyer is a link "to be removed from our list" that sends us an email.

At present someone either downloads and opens the txt file in notepad, searches and removes the email, then uploads it back to the server, OR an admin edits the raw file on the server itself.

 

I want a management form that reads testFile.txt into a form "textarea", allows manual editing, then on submit, saves the revised testFile.txt.

 

The code I posted, opens the file, allows editing, but doesn't save the edited file on submit - it just reloads the original file.

 

Link to comment
https://forums.phpfreaks.com/topic/144992-revise-a-text-file/#findComment-761486
Share on other sites

Permission is 777, I removed enctype.

 

The problem is that the testFile.txt is not being re-written to, submit is not sending textfield data - the page simply shows the same file on submit.

 

I thought the problem would stand out as embarrassingly elementary.

 

<?php
if (isset($_POST['SaveEmail']))
{
    $open = fopen('testFile.txt','w+');
    $text = $_POST['EditList'];
    fwrite($open, $text);
    fclose($open);
    echo "Gig list updated.";
}

    
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>test create a file</title>
</head>
<body>

<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
  <p>
    <textarea id="FormsMultiLine3" name="EditList" rows="27" cols="79" style="width: 645px; white-space: pre;">
<?php 
    $filename = "testFile.txt";
    $fh = fopen($filename, "r+");
    $data = fread($fh, filesize($filename));
    fclose($fh);
echo $data; 
?>
</textarea>
  </p>
  <p>
    <input type="submit" id="FormsButton1" name="SaveEmail" value="Save" style="height: 24px; width: 57px;">
  </p>
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/144992-revise-a-text-file/#findComment-763538
Share on other sites

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.