File Attachments

View: New views
6 Messages — Rating Filter:   Alert me  

File Attachments

by Jim Summers-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello All,

Now I am trying to attach a file.  I am trying to do it with the
following code:
===
$attach1 = $_FILES['ou_transcript']['tmp_name'];
$encoding = "base64";
$type = "application/octet-stream";

$mail->AddStringAttachment($attach1,"testattach",$encoding,$type);
===

Which does create an attachment named 'testattach', but it is empty.  I
was hoping to use the AddStringAttachment so I would not have to
actually try and save the uploaded file and then later remove it.

 From what I have read the $_FILES array automatically uploads the
user's file to a temporary area.  Is that right.  Do I need to do
anything after the form has been submitted and before I attach?

Ideas / Suggestions?

TIA

--
Jim Summers
Computer Science - University of Oklahoma


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Phpmailer-general mailing list
Phpmailer-general@...
https://lists.sourceforge.net/lists/listinfo/phpmailer-general

Re: File Attachments

by Chris Weiss-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Jun 11, 2009 at 11:10 AM, Jim Summers <jsummers@...> wrote:
>
>  From what I have read the $_FILES array automatically uploads the
> user's file to a temporary area.  Is that right.  Do I need to do
> anything after the form has been submitted and before I attach?

that's right, the array should say where it is

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Phpmailer-general mailing list
Phpmailer-general@...
https://lists.sourceforge.net/lists/listinfo/phpmailer-general

Re: File Attachments

by Jim Summers-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Chris Weiss wrote:
> On Thu, Jun 11, 2009 at 11:10 AM, Jim Summers <jsummers@...> wrote:
>>  From what I have read the $_FILES array automatically uploads the
>> user's file to a temporary area.  Is that right.  Do I need to do
>> anything after the form has been submitted and before I attach?
>
> that's right, the array should say where it is

I found the following in the error_log on the server:

PHP Notice:  Undefined index:  ou_transcript

Do I need to configure something in the php on the webserver to allow
for uploads?  I checked for typos in the form and in the php script and
did not see any.

TIA


--
Jim Summers
Computer Science - University of Oklahoma


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Phpmailer-general mailing list
Phpmailer-general@...
https://lists.sourceforge.net/lists/listinfo/phpmailer-general

Re: File Attachments

by Chris Weiss-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

well, you need to turn on the feature, set the max size to something
good for you, and make sure the upload temp dir is writable by the web
server, and use the right form type.  php's online manual should have
the info with examples.

ou_transcript isn't a php thing though, that must be something with your code

On Thu, Jun 11, 2009 at 11:32 AM, Jim Summers <jsummers@...> wrote:

>
>
> Chris Weiss wrote:
>>
>> On Thu, Jun 11, 2009 at 11:10 AM, Jim Summers <jsummers@...> wrote:
>>>
>>>  From what I have read the $_FILES array automatically uploads the
>>> user's file to a temporary area.  Is that right.  Do I need to do
>>> anything after the form has been submitted and before I attach?
>>
>> that's right, the array should say where it is
>
> I found the following in the error_log on the server:
>
> PHP Notice:  Undefined index:  ou_transcript
>
> Do I need to configure something in the php on the webserver to allow for
> uploads?  I checked for typos in the form and in the php script and did not
> see any.
>
> TIA
>
>
> --
> Jim Summers
> Computer Science - University of Oklahoma
>
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Phpmailer-general mailing list
Phpmailer-general@...
https://lists.sourceforge.net/lists/listinfo/phpmailer-general

Re: File Attachments

by Jim Summers-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


The key to success was to specify ENCTYPE="multipart/form-data" for the
form.

Also when you start getting into files over 1M in size you will probably
have to up the memory_limit in php.ini or I think it can be set in your
script also.

I am going to keep plugging along with the AddStringAttachment to see if
I can move the file without having to save it on the server and then
attach and then after the send unlink it.

Thanks Again

Chris Weiss wrote:

> well, you need to turn on the feature, set the max size to something
> good for you, and make sure the upload temp dir is writable by the web
> server, and use the right form type.  php's online manual should have
> the info with examples.
>
> ou_transcript isn't a php thing though, that must be something with your code
>
> On Thu, Jun 11, 2009 at 11:32 AM, Jim Summers <jsummers@...> wrote:
>>
>> Chris Weiss wrote:
>>> On Thu, Jun 11, 2009 at 11:10 AM, Jim Summers <jsummers@...> wrote:
>>>>  From what I have read the $_FILES array automatically uploads the
>>>> user's file to a temporary area.  Is that right.  Do I need to do
>>>> anything after the form has been submitted and before I attach?
>>> that's right, the array should say where it is
>> I found the following in the error_log on the server:
>>
>> PHP Notice:  Undefined index:  ou_transcript
>>
>> Do I need to configure something in the php on the webserver to allow for
>> uploads?  I checked for typos in the form and in the php script and did not
>> see any.
>>
>> TIA
>>
>>
>> --
>> Jim Summers
>> Computer Science - University of Oklahoma
>>
>>

--
Jim Summers
Computer Science - University of Oklahoma


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Phpmailer-general mailing list
Phpmailer-general@...
https://lists.sourceforge.net/lists/listinfo/phpmailer-general

Re: File Attachments

by andy.prevost :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The only two pieces of code you need to get this working is:

if ( $_FILES ) {
  $img = file_get_contents($_FILES['frmImg']['tmp_name']);

The first if() statement checks to see if there is uploaded files.

The second one gets the temp file upload into a string variable.

You do not have to unlink, it is in the temp file directory and will be
automatically deleted when the script terminates.

>From the string variable, you can use the AddStringAttachment  function.

PS. Just make sure you replace 'frmImg' with your own form input field name.

Andy
--------------------------------------------------
From: "Jim Summers" <jsummers@...>
Sent: Thursday, June 11, 2009 5:22 PM
To: "Chris Weiss" <cweiss@...>
Cc: <phpmailer-general@...>
Subject: Re: [Phpmailer-general] File Attachments

>
> The key to success was to specify ENCTYPE="multipart/form-data" for the
> form.
>
> Also when you start getting into files over 1M in size you will probably
> have to up the memory_limit in php.ini or I think it can be set in your
> script also.
>
> I am going to keep plugging along with the AddStringAttachment to see if
> I can move the file without having to save it on the server and then
> attach and then after the send unlink it.
>
> Thanks Again
>
> Chris Weiss wrote:
>> well, you need to turn on the feature, set the max size to something
>> good for you, and make sure the upload temp dir is writable by the web
>> server, and use the right form type.  php's online manual should have
>> the info with examples.
>>
>> ou_transcript isn't a php thing though, that must be something with your
>> code
>>
>> On Thu, Jun 11, 2009 at 11:32 AM, Jim Summers <jsummers@...> wrote:
>>>
>>> Chris Weiss wrote:
>>>> On Thu, Jun 11, 2009 at 11:10 AM, Jim Summers <jsummers@...>
>>>> wrote:
>>>>>  From what I have read the $_FILES array automatically uploads the
>>>>> user's file to a temporary area.  Is that right.  Do I need to do
>>>>> anything after the form has been submitted and before I attach?
>>>> that's right, the array should say where it is
>>> I found the following in the error_log on the server:
>>>
>>> PHP Notice:  Undefined index:  ou_transcript
>>>
>>> Do I need to configure something in the php on the webserver to allow
>>> for
>>> uploads?  I checked for typos in the form and in the php script and did
>>> not
>>> see any.
>>>
>>> TIA
>>>
>>>
>>> --
>>> Jim Summers
>>> Computer Science - University of Oklahoma
>>>
>>>
>
> --
> Jim Summers
> Computer Science - University of Oklahoma
>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> Phpmailer-general mailing list
> Phpmailer-general@...
> https://lists.sourceforge.net/lists/listinfo/phpmailer-general 


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Phpmailer-general mailing list
Phpmailer-general@...
https://lists.sourceforge.net/lists/listinfo/phpmailer-general