Jump to content

Recommended Posts

I'm trying to create a script to send multiple attachments with one email.  I'm using an array to store the attachments and then trying to use a foreach loop to email them.  However for some reason my array seems to be empy.  This is my html

 

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

 

And this is my php code

 

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

$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);

Link to comment
https://forums.phpfreaks.com/topic/203270-array-not-working/
Share on other sites

Your code has no error checking logic in to to test if the upload worked or failed.

 

You must always test for any possible errors and validate data before you attempt to reference that data.

 

Ref: http://us.php.net/manual/en/features.file-upload.errors.php

 

Also see Example #3 at the following link for an example of code that at least tests the ['error'] element of the uploaded data - http://us.php.net/manual/en/features.file-upload.post-method.php

 

 

Link to comment
https://forums.phpfreaks.com/topic/203270-array-not-working/#findComment-1064991
Share on other sites

I used error checking to check if the the variables $value['tmp_name'] etc had anything in them and they came back as empty however I deleted this code to simplify it when copying it to here. 

 

I also used the following code to check the contents of the array and everything seem find so there must be something wrong in my foreach loop.  Hope that makes sense. 

 

if (isset($_POST['submit'])) {
echo '<pre>' . print_r($_FILES,true) . '</pre>';
}

Link to comment
https://forums.phpfreaks.com/topic/203270-array-not-working/#findComment-1064995
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.