Page 2 of 3

Posted: Wed Apr 18, 2007 6:32 am
by Chris Corbyn
AshP wrote:$save_path is defined near the top of the php code - its the directory that uploaded files are saved to...

I have been looking at the Rad documentation regarding upload handeling, does this make any sense to you? http://www.radinks.com/upload/upload.php
$file_path should be the full path to the file Swift needs to attach. It can't attach a directory ;)

I had a look over the documentation (it looks poorly written by the way with short_tags and register_globals) and couldn't find what I was looking for so I'm going to take a completely wild stab in the dark and say to try this:

Code: Select all

//If an attachment was sent, attach it
$file_path = false;
$file_name = false;
$file_type = false;
if (!empty($_FILES["userfile"]["tmp_name"][0]))
{
    if (!$_FILES["userfile"]["error"][0])
    {
        $file_path = $save_path . $_FILES["userfile"]["name"][0];
        $file_name = $_FILES["userfile"]["name"][0];
        $file_type = $_FILES["userfile"]["type"][0];
    }
}
It probably won't work because it's just an educated guess of what RAD might be doing.

Posted: Wed Apr 18, 2007 6:45 am
by AshP
mate, that was a very good stab in the dark - attachment working a-ok! :D :D :D

HOWEVER - only one file gets sent when i attach more than one file - any ideas? :lol:

Also I still get the error message even when the file has uploaded & sent ok?:
array(1) { ["userfile"]=> array(5) { ["name"]=> array(1) { [0]=> string(12) "DSC00035.jpg" } ["type"]=> array(1) { [0]=> string(10) "image/jpeg" } ["tmp_name"]=> array(1) { [0]=> string(14) "/tmp/phpCtWoiz" } ["error"]=> array(1) { [0]=> int(0) } ["size"]=> array(1) { [0]=> int(123550) } }}string(43) "/public_html/tmp/DSC00035.jpg"

Posted: Wed Apr 18, 2007 7:19 am
by Chris Corbyn
AshP wrote:mate, that was a very good stab in the dark - attachment working a-ok! :D :D :D

HOWEVER - only one file gets sent when i attach more than one file - any ideas? :lol:

Also I still get the error message even when the file has uploaded & sent ok?:
array(1) { ["userfile"]=> array(5) { ["name"]=> array(1) { [0]=> string(12) "DSC00035.jpg" } ["type"]=> array(1) { [0]=> string(10) "image/jpeg" } ["tmp_name"]=> array(1) { [0]=> string(14) "/tmp/phpCtWoiz" } ["error"]=> array(1) { [0]=> int(0) } ["size"]=> array(1) { [0]=> int(123550) } }}string(43) "/public_html/tmp/DSC00035.jpg"
*sighs* :)

It's a fairly considerable change so I just scripted it out for you (untested of course since I'm not running RAD).

Code: Select all

//If an attachment was sent, attach it
// $file_path = false;
// $file_name = false;
// $file_type = false;
// if (!empty($_FILES["userfile"]["tmp_name"][0]))
// {
//     if (!$_FILES["userfile"]["error"][0])
//     {
//         $file_path = $_FILES["userfile"]["tmp_name"][0];
//         $file_name = $_FILES["userfile"]["name"][0];
//         $file_type = $_FILES["userfile"]["type"][0];
//     }
// }

 //attachment code
// if ($file_paths && $file_name && $file_type)
// {
//     $message->attach(
//         new Swift_Message_Attachment(new Swift_File($file_path), $file_name, $file_type));
// }

$file_paths = array();
$file_names = array();
$file_types = array();
if (!empty($_FILES["userfile"]["tmp_name"]))
{
    foreach (array_keys($_FILES["userfile"]["tmp_name"]) as $key)
    {
        if (!$_FILES["userfile"]["error"][$key])
        {
            $file_paths[$key] = $save_path . $_FILES["name"][$key];
            $file_names[$key] = $_FILES["userfile"]["name"][$key];
            $file_types[$key] = $_FILES["userfile"]["type"][$key];
        }
    }
}

foreach ($file_paths as $key => $file)
{
    $message->attach(
        new Swift_Message_Attachment(new Swift_File($file), $file_names[$key], $file_types[$key]));
}

Posted: Wed Apr 18, 2007 7:23 am
by Chris Corbyn
AshP wrote:Also I still get the error message even when the file has uploaded & sent ok?:
array(1) { ["userfile"]=> array(5) { ["name"]=> array(1) { [0]=> string(12) "DSC00035.jpg" } ["type"]=> array(1) { [0]=> string(10) "image/jpeg" } ["tmp_name"]=> array(1) { [0]=> string(14) "/tmp/phpCtWoiz" } ["error"]=> array(1) { [0]=> int(0) } ["size"]=> array(1) { [0]=> int(123550) } }}string(43) "/public_html/tmp/DSC00035.jpg"
That's not an error message. It's the var_dump() stuff I asked you to add before. Just remove the calls to var_dump(). I've removed them in my code above.

Posted: Wed Apr 18, 2007 9:13 am
by AshP
alright mate,

just tried the code that you sent me, it now sends multiple file attachments with name and file type intact ok, however they are corrupt!

almost there, its just trying to be annoying now :twisted:

Posted: Wed Apr 18, 2007 9:25 am
by Chris Corbyn
Oops, I made a typo:

Code: Select all

$file_paths = array();
$file_names = array();
$file_types = array();
if (!empty($_FILES["userfile"]["tmp_name"]))
{
    foreach (array_keys($_FILES["userfile"]["tmp_name"]) as $key)
    {
        if (!$_FILES["userfile"]["error"][$key])
        {
            $file_paths[$key] = $save_path . $_FILES["userfile"]["name"][$key];
            $file_names[$key] = $_FILES["userfile"]["name"][$key];
            $file_types[$key] = $_FILES["userfile"]["type"][$key];
        }
    }
}

foreach ($file_paths as $key => $file)
{
    $message->attach(
        new Swift_Message_Attachment(new Swift_File($file), $file_names[$key], $file_types[$key]));
}
I forgot the "userfile" index in the array. That should work now :)

Posted: Wed Apr 18, 2007 9:40 am
by AshP
dude you are a genius - it works!

will send you some beer money for oz :wink:

bit of a random one, but may i ask what your day job is?

Posted: Wed Apr 18, 2007 9:41 am
by Chris Corbyn
AshP wrote:dude you are a genius - it works!

will send you some beer money for oz :wink:

bit of a random one, but may i ask what your day job is?
Thank you :) Much appreciated.

:lol:

Surprise you it may not, but I'm a PHP Developer. I'm sat in my office right now, browsing DevNet when I should be working but the sun out of my window is telling me to get up and go home.

Posted: Thu Apr 19, 2007 7:17 am
by AshP
what sort of stuff are you ment to be working on then? :lol:

im afraid i may need your help again - emails and attachments work great, however, when i try and send emails to certain addresses the emails do not seem to come through!

i know it does not really make sense because in theory if you can send an email to one address you should be able to send an email to any address, right?

but if you are trying to send an email to a different domain for example, can this cause problems?

Posted: Thu Apr 19, 2007 7:34 am
by Chris Corbyn
I work on a system which stores and analyses behaviour records for schools in the UK. It's *yawn* really fun *yawn* of course.

Sounds like the mail server you're connecting to is not an outgoing relay server. Many SMTP servers are simply configured to accept mail for their own domains only (take Hotmail's servers for example). Ask your host what the name of their outgoing SMTP server is ;) It may be that you have to use the Sendmail connection instead if it's a linux server.

Posted: Thu Apr 19, 2007 8:38 am
by AshP
sounds interesting - are you well paid for your skills(if you dont mind me asking)?

I am pretty sure we are using linux servers - I'm not quite sure that I follow you though about the hotmail thing though, as they receive mail from any account?(sorry for saying such a stupid thing as you clearly know what your talking about)!

is the sendmail connection easy to do?

Posted: Thu Apr 19, 2007 11:24 am
by AshP
alright mate, have used the sendmail command and that has sorted my email problems, however there is yet another problem (the last one i promise!)

basically the email & attachments are sent to an online database which then puts them in a queue of jobs to do - however - the database keeps returning emails saying there was nothing attached to the email when there blatantly was?! does swift attach things differently to normal? cheers dude

Posted: Thu Apr 19, 2007 3:47 pm
by Chris Corbyn
AshP wrote:sounds interesting - are you well paid for your skills(if you dont mind me asking)?
Sadly not. Well... It depends upon what you consider well-paid I guess ;) The project is currently mostly supported by external funding so pulling salaries from that doesn't leave much for us.

Swift doesn't attach things differently to normal no. I'd have to see the code to understand how you're dealing with this.

Posted: Wed Apr 25, 2007 9:12 am
by AshP
hello again...

have kind of sorted out the whole mailing problem now, howveer have anoter problem (nothing to do with swiftmailer i dont think, but you seem to know everything!)

basically i am not able to upload a file that is over 2MB

At first i thought it was somthing to do with the php.ini file (as its default setting is to not allow any uploads over 2MB) so i got my host to change the max_upload setting to 10mb, this has not fixed the problem however.

I then thought maybe it was to do with the max_input_time so I added set_time_limit(120); to my script but this has not sorted it....

Any ideas dude?

also i may possibly have some work on the side for you if it would be something you were interested in (and it comes through!)?

:wink:

Posted: Wed Apr 25, 2007 9:14 am
by Chris Corbyn
post_max_size ?

:)