?
Solved

PHP File Attachment Size

Posted on 2007-07-31
9
Medium Priority
?
1,839 Views
Last Modified: 2008-02-01
I am using imap_fetchbody to get the attachments out of an e-mail.... but if the attachment is too large, I get an "Internal Server Error"... I am sure this is because of a timeout or something...

so 2 questions,

1.) How do i set the timeouts so this does not happen....
2.) How can I get the attachment file size before I grab it with the "imap_fetchbody" function?
0
Comment
Question by:JoshWegener
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Assisted Solution

by:Oscurochu
Oscurochu earned 664 total points
ID: 19606239
set_time_limit(0) disables timeouts. (http://us.php.net/manual/en/function.set-time-limit.php)
0
 
LVL 14

Assisted Solution

by:ygoutham
ygoutham earned 332 total points
ID: 19606341
in the php.ini file there is always a restriction on fileupload sizes

there are also restrictions on individual scripts using certain amount of memory and execution time

probably you need to look at all this and then restart the httpd process so that the new php.ini takes effect

if the file were to be so large that it exceeds the maximum execution time or the default browser timeout then there is not much that you can do.  
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 672 total points
ID: 19606646
timeout has to be set on the server, I doubt that the application (PHP here) can change this value

for the IMAP mail sizes: you have to issue an IMAP command (if your IMAP server supports it) like:
   b42 uid fetch 1:* (flags rfc822.size)

don't know how this is done with PHP, but I guess that there is a function for it (somewhere, beside the infinite other functions:)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Assisted Solution

by:Oscurochu
Oscurochu earned 664 total points
ID: 19606671
ahoffmann, PHP does have a function that changes (or disables) timeouts. PHP is part of the server, hence I don't doubt that php would be able to change the value.
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 332 total points
ID: 19606764
1) maybe you don't get a timeout, more a memory-limit execeeced. Check memory_limit on your php-server
2) To get the size of a message see http://www.php.net/manual/en/function.imap-fetchstructure.php
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 672 total points
ID: 19606787
> PHP is part of the server, ..
no, it just may be a module inside the server
you can set the limit for that module (or CGI) but not the limit for server calling the module (or CGI) from within php (a child cannot change it's parent, obviously:)
Things might be different if you web server is PHP itself ...
0
 
LVL 1

Author Comment

by:JoshWegener
ID: 19607957
1.) How do i set the timeouts so this does not happen....
     A:) Change the PHP.ini file

2.) How can I get the attachment file size before I grab it with the "imap_fetchbody" function?
     A:) ????????
0
 
LVL 1

Author Comment

by:JoshWegener
ID: 19608051
After much work.. I found it....

$struckture->parts[$key]->bytes


----------------------------------------------------------------
      function GetAttech($mid,$path,$id) // Get Atteced File from Mail
      {
            $struckture = imap_fetchstructure($this->marubox,$mid);
            $ar="";
            foreach($struckture->parts as $key => $value)
            {
                  $enc=$struckture->parts[$key]->encoding;
                  if($struckture->parts[$key]->ifdparameters)
                  {
                        $name=$struckture->parts[$key]->dparameters[0]->value;
                        $message = imap_fetchbody($this->marubox,$mid,$key+1);
                        if ($enc == 0)
                              $message = imap_8bit ($message);
                        if ($enc == 1)
                              $message = imap_8bit ($message);
                        if ($enc == 2)
                              $message = imap_binary ($message);
                        if ($enc == 3)
                              $message = imap_base64 ($message);
                        if ($enc == 4)
                              $message = quoted_printable_decode($message);
                        if ($enc == 5)
                              $message = $message;
                        if ( ($struckture->parts[$key]->bytes / 1024 / 1024) > 2 ) {
                              $name = 'Upload Too Large.jpg';
                        } else {
                              if ( strlen($name) >= 200 )
                                    $name = substr($name, -200);
                              $name = '1' . $id . rand(5,1000) . '3_' . $name;
                              $fp=fopen($path.$name,"w");
                              fwrite($fp,$message);
                              fclose($fp);
                        }
                        $ar=$ar.$name.",";
                  }
            }
            $ar=substr($ar,0,(strlen($ar)-1));
            return $ar;
      }
----------------------------------------------------------------
0
 
LVL 1

Author Comment

by:JoshWegener
ID: 19608054
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question