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
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
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
Share on other sites

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.