Reading a local file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leoden
Forum Newbie
Posts: 21
Joined: Sat May 24, 2003 8:48 pm

Reading a local file

Post 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
Sinnix
Forum Commoner
Posts: 43
Joined: Mon Apr 28, 2003 11:01 am
Location: Ottawa, ON Canada
Contact:

Post by Sinnix »

Well, for starters, why don't you upload your PHP code for us to have a look at. ;)
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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);
?>
Post Reply