Jump to content

Recommended Posts

Can anyone help me.  I've been trying for days to get this script to work.  What I'm trying to do is to create a script which sends mulitple email attachments.  I've have copied below my html form and my php code.  At the moment I think I have a problem with my array.  as I'm getting this error - Warning: fread(): supplied argument is not a valid stream resource.  Any help will be very greatly appreciated. 

 

<form method="post" action="order_success2.php" enctype="multipart/form-data">
<ul>
<li class="clear"><input type="file" name="att[]" size="26" /></li>
<li><input type="file" name="att[]" size="26" /></li>
<li class="clear"><input type="submit" name="submit" value="Submit!" /></li>
</ul>
</form>

 

<?php 

$to = "someone@gmail.com"; 

foreach($_FILES['att'] as $key => $value){
echo '<pre>' . print_r($value,true) . '</pre>';
$att_path = $value['tmp_name'];
$att_name = $value['name'];
$att_size = $value['size'];
$att_type = $value['type'];

$fp = fopen( $att_path, "rb");
$file = fread( $fp, $att_size );
fclose ($fp);

$num = md5(time());
$str = "==multipart_Boundary_x{$num}x";

$file = chunk_split(base64_encode($file));

$subject = "You have been sent some content by " . $_REQUEST['order_company_name']; 

$email = $_REQUEST['order_email'] ; 
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/mixed;";
$headers .= "boundary=\"{$str}\"\r\n";
$headers .= "From: $email"; 

$msg .= "This is a multi-part message in MIME format\r\n\n";
$msg .= "--{$str}\r\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding: 8bit\r\n";
$msg .= "--{$str}\r\n";

$msg .= "Content-Type: {$att_type}; ";
$msg .= "name=\"{$att_name}\"\r\n";
$msg .= "Content-Disposition: attachment; ";
$msg .= "filename =\"{$att_name}\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "$file\r\n\n";
$msg .= "--{$str}";

$sent = mail($to, $subject, $msg, $headers) ; 
if($sent) 
{print "Thank you.  Your attachments were sent successfully"; }
else 
{print "Sorry.  We encountered an error sending your mail"; }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/203276-can-anyone-out-there-help-me/
Share on other sites

You do realize that when you have an existing active thread for a problem and you start a new thread for that same problem, that you loose the history of how you go to this point and surprisingly creating more threads for the same problem actually gets you less help than you would have gotten if you had continued with your original thread.

I know.  It's just that I'm under pressure to get this done and its frustrating when you've been working on it for a long time and getting nowhere.  I know that it was cycling through the array wrong and have tried to change my code.  The variable $value['tmp_name'] however returns 'array' instead of the file path.  Causing this error.  I'm not sure why this is happening. 

 

foreach($_FILES as $key => $value){
$att_path = $value['tmp_name'];
$att_name = $value['name'];
$att_size = $value['size'];
$att_type = $value['type'];

echo($value['tmp_name']);

$fp = fopen( $att_path, "rb");
$file = fread( $fp, $att_size );
fclose ($fp);

foreach ($_FILES['att']['error'] as $key => $error) {

  if (UPLOAD_ERR_OK === $error) {

    $name = $_FILES['att']['name'][$key];

    ..

  }

}

 

Instead of creating multiple threads you could have searched/browsed the manual and you would have found a very detailed explanation at http://php.net/manual/en/features.file-upload.post-method.php

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.