Page 1 of 1

Reading a local file

Posted: Mon Sep 15, 2003 10:16 am
by leoden
Hello guys could someone help me with a little problem.

I am trying to write a prog that lets me email a newsletter to people who have registered on my website using the following steps

1) User writes newsletter, saves as plain text file

2) visits admin webpage, browse for local file, then submit

3) file is read the email to all users who request it.

After having a look at 'file' type in forms i created the form section of the page as follows

Code: Select all

<form name="emailnewsletter" method="post" action="<? $PHP_SELF ?>" ENCTYPE="application/x-www-form-urlencoded">
  <table width="82%" border="1" cellpadding="0" cellspacing="0" bordercolor="#999933">
    <tr bordercolor="#009966"> 
      <td width="26%"><div align="center"><font color="#009966"><strong>Sale Number</strong></font></div></td>
      <td width="17%"> <div align="left">
          <input name="salenumber" type="text" id="salenumber" size="10" maxlength="3">
        </div></td>
      <td width="57%">
	  <input type="file" size=40 name="file">
	  <input name="submit_leo" type="submit" id="testleo3" value="Test to Leo">
        <input name="submit_denhams" type="submit" id="testdenhams4" value="Test to Denhams">
        <input name="submit" type="submit" id="submit" value="Submit"></td>
    </tr>
  </table>
</form>
after this is submitted the variable $_FILES['file'] containes an encoded array. All i need is the plain text version of the file. When I change the ENCTYPE to 'plain text etc', $_FILES['file'] contains nothing.

Any ideas

Posted: Mon Sep 15, 2003 10:27 am
by Sinnix
Well, for starters, why don't you upload your PHP code for us to have a look at. ;)

Posted: Mon Sep 15, 2003 3:15 pm
by m3rajk
here's an idea: users uploads file to the server via a script that checks it for somet hings.. like to make sure it's not maliicuios

another file has this set up and is called wehn you try ti send it:

Code: Select all

<?php
# path to the dir witht he e-mailable files
$dir=getcwd().'/emailable_files/';
# get the filename 
$file_to_email=$dir.$_GET['email_file'];

$file; // empty variable for the file

if(is_file($file_to_email)){
  /* set the variable $file tot he contents of the file */
}

/* connect to db and get the e-mail addresses */

mail($to, 'the newsletter', $file, $email_header_info);
?>