Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 38

Thread: Mobile upload script request

  1. #21
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    and would i be better off to use a database for this or just keep it simple with a php file and folder?

  2. #22
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Either way; however, I believe that a database would make it run a little bit faster as it wouldn't have to read the directory every time the script is accessed. Then again; if you go the route of the db, if you delete an image from the directory and forget to delete that entry from the db, then there will be missing images in the gallery.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #23
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    that would be great. thank you so much

  4. #24
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    here is my mail settings because i cannot get this to work so im not sure what im doing wrong

    Mail Server Username: mobile+portlandnightlifeonline.com
    Incoming Mail Server: mail.portlandnightlifeonline.com
    Incoming Mail Server: (SSL) mail.portlandnightlifeonline.com
    Outgoing Mail Server: mail.portlandnightlifeonline.com (server requires authentication) port 26
    Outgoing Mail Server: (SSL) mail.portlandnightlifeonline.com (server requires authentication) port 26
    Supported Incoming Mail Protocols: POP3, POP3S (SSL/TLS), IMAP, IMAPS (SSL/TLS)
    Supported Outgoing Mail Protocols: SMTP, SMTPS (SSL/TLS)


    and here is my file tree of where my email is in my dir
    /mail/portlandnightlifeonline.com/mobile


    and here is my index.phps file

    Code:
     <?php
    $cfg = array();
    ######## CONFIG #######
    $cfg['upload_dir'] = 'demo'; //what directory to upload images to $cfg['mail_server'] = 'mail.portlandnightlifeonline.com'; //email server $cfg['mail_port'] = '26'; //email server port
     
    /* email server services as described on http://php.net/imap_open */ $cfg['mail_services'] = '/mail/portlandnightlifeonline.com/mobile';
     
    $cfg['mail_username'] = 'username'; //username for the email address to check $cfg['mail_password'] = 'password'; //password for above user $cfg['debug'] = false; //true or false for debugging
     
    /* Accepted File Types: if less than four characters, use a dot as the first char. */ $cfg['accepted'] = array('.3g2','.png','.jpg','.jpe','jpeg','.gif');
    ######## END CONFIG #########
     
    $pid=2;
     
    $type = array('text', 'multipart', 'message', 'application', 'audio', 'image', 'video', 'other'); $encoding = array('7bit', '8bit', 'binary', 'base64', 'quoted-printable', 'other');
     
    if(!is_dir($cfg['upload_dir'])) {
      @mkdir($cfg['upload_dir']) or die('Cannot create directory:
    '.$cfg['upload_dir'].'! Make sure the parent folder has write permissions'); }
     
    // open POP connection
    $inbox = @imap_open
    ('{'.$cfg['mail_server'].':'.$cfg['mail_port'].$cfg['mail_services'].'}',
    $cfg['mail_username'], $cfg['mail_password']) or die('Connection to server failed.');
     
    // parse message body
    function parse($structure) {
    global $type;
    global $encoding;
     
    // create an array to hold message sections $ret = array();
     
    // split structure into parts
    $parts = $structure->parts;
     
     for($x=0; $x<sizeof($parts); $x++) {
      $ret[$x]['pid'] = ($x+1);
      $that = $parts[$x];
     
    // default to text
      if ($that->type == '') {
       $that->type = 0;
      }
      $ret[$x]['type'] = $type[$that->type] . '/' . strtolower($that->subtype);
     
    // default to 7bit
      if ($that->encoding == '') {
       $that->encoding = 0;
      }
     
      $ret[$x]['encoding'] = $encoding[$that->encoding];
      $ret[$x]['size'] = strtolower($that->bytes);
      $ret[$x]['disposition'] = strtolower($that->disposition);
     
      if ($that->ifparameters == 1) {
       $params = $that->parameters;
     
       foreach ($params as $p) {
        if($p->attribute == 'NAME') {
         $ret[$x]['name'] = $p->value;
         break;
        }
       }
      }
     }
     return $ret;
    }
     
    function get_attachments($arr) {
     for($x=0; $x < sizeof($arr); $x++) {
      if($arr[$x]['disposition'] == 'attachment') {
       $ret[] = $arr[$x];
      }
     }
     return $ret;
    }
     
    $count = @imap_num_msg($inbox) or die('No Messages in mailbox!'); //echo 'count: ' . $count;
     
    // get message headers and structure
    for ($c = 1; $c <= $count; $c++) {
     $id = $c;
     $headers = imap_header($inbox, $id);
     $structure = imap_fetchstructure($inbox, $id);
     
    // if multipart, parse
     if(sizeof($structure->parts) > 1) {
      $sections = parse($structure);
      $attachments = get_attachments($sections);  }
     
    if ($cfg['debug']) {
     echo 'Structure of message: ' . $id . '<BR><pre>';  print_r($structure);  echo '</pre><BR>';  echo 'Sections of message: ' . $id . '<BR><pre>';  print_r($sections);  echo '</pre><BR>'; }
     
    // look for specified part
     for($x=0; $x<sizeof($sections); $x++) {
      if($sections[$x]['pid'] == $pid) {
        $dtype = $sections[$x]['type'];
        $dencoding = $sections[$x]['encoding'];
        $filename = $sections[$x]['name'];
      }
     }
     
    if ($cfg['debug']) {
     echo ' type: ' . $dtype . '<BR>';
     echo 'encoding: ' . $dencoding . '<BR>';  echo 'filename: ' . $filename . '<BR>';  echo ' id: ' . $id . '<BR><BR>'; }
     
    $attachment = imap_fetchbody($inbox, $id, $pid);
     
    if (!$cfg['debug']) {
     
     //if (in_array(substr($filename, -4), $cfg['accepted'])) {
      if ($dencoding == 'base64') {
      // Decode and save attachment to a file
       list($usec, $sec) = explode(' ', microtime());
       $usec = substr($usec,2,3);
       $name = date('Ymd.His');
       $fp=fopen($cfg['upload_dir'].'/'.$name.'_'.$filename,'w');
       fwrite($fp,imap_base64($attachment));
       fclose($fp);
      }
     //}
    }
     
    }
     
    if (!$cfg['debug']) {
    // delete all emails
    for ($i = 1; $i <= $count; $i++) {
    imap_delete($inbox, $i);
    }
    imap_expunge($inbox);
    }
     
    imap_close($inbox);
     
    if (!$cfg['debug']) {
    header('Location: '.$cfg['upload_dir']); } ?>
    Last edited by thetestingsite; 12-07-2007 at 01:32 AM. Reason: removed username/password

  5. #25
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    On these lines, change to the highlighted values:

    Code:
    $cfg['mail_server'] = 'mail.portlandnightlifeonline.com'; //email server 
    $cfg['mail_port'] = '110'; //email server port
     
    /* email server services as described on http://php.net/imap_open */ 
    $cfg['mail_services'] = '/pop3';
     
    $cfg['mail_username'] = 'YOUR_USERNAME@YOUR_DOMAIN.com'; //username for the email address to check 
    $cfg['mail_password'] = 'YOUR_PASSWORD'; //password for above user $cfg['debug'] = false; //true or false for debugging
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #26
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i still get nothing. here is the link
    ive sent a few.


    does it matter that i use horde to check my mail?

    here is the url for my mail


    i am so lost right now. dont understand why it works for you but not for me
    Last edited by davidjmorin; 12-07-2007 at 02:50 AM. Reason: edit link

  7. #27
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Ok, I played around with it from the user information you posted earlier (before editing to remove the info) ) and have come up with the following:

    Code:
    <?php
    $cfg = array();
    ######## CONFIG #######
    $cfg['upload_dir'] = 'demo'; //what directory to upload images to
    $cfg['mail_server'] = 'mail.portlandnightlifeonline.com'; //email server
    $cfg['mail_port'] = '110'; //email server port
    
    /* email server services as described on http://php.net/imap_open */
    $cfg['mail_services'] = '/pop3/notls'; 
    
    $cfg['mail_username'] = 'username@portlandnightlifeonline.com'; //username for the email address to check
    $cfg['mail_password'] = 'password'; //password for above user
    $cfg['debug'] = false; //true or false for debugging
    
    /* Accepted File Types: if less than four characters, use a dot as the first char. */
    $cfg['accepted'] = array('.png','.jpg','.jpe','jpeg','.gif');
    ######## END CONFIG #########
    
    $pid=2;
    
    $type = array('text', 'multipart', 'message', 'application', 'audio', 'image', 'video', 'other');
    $encoding = array('7bit', '8bit', 'binary', 'base64', 'quoted-printable', 'other');
    
    if(!is_dir($cfg['upload_dir'])) {
      @mkdir($cfg['upload_dir']) or die('Cannot create directory: '.$cfg['upload_dir'].'! Make sure the parent folder has write permissions');
    }
    
    // open POP connection
    $inbox = @imap_open ('{'.$cfg['mail_server'].':'.$cfg['mail_port'].$cfg['mail_services'].'}', $cfg['mail_username'], $cfg['mail_password']) or die('Connection to server failed. Error: <BR>'.imap_last_error());
    
    // parse message body
    function parse($structure) {
    global $type;
    global $encoding;
    
    // create an array to hold message sections
    $ret = array();
    
    // split structure into parts
    $parts = $structure->parts;
    
     for($x=0; $x<sizeof($parts); $x++) {
      $ret[$x]['pid'] = ($x+1);
      $that = $parts[$x];
    
    // default to text
      if ($that->type == '') {
       $that->type = 0;
      }
      $ret[$x]['type'] = $type[$that->type] . '/' . strtolower($that->subtype);
    
    // default to 7bit
      if ($that->encoding == '') {
       $that->encoding = 0;
      }
    
      $ret[$x]['encoding'] = $encoding[$that->encoding];
      $ret[$x]['size'] = strtolower($that->bytes);
      $ret[$x]['disposition'] = strtolower($that->disposition);
    
      if ($that->ifparameters == 1) {
       $params = $that->parameters;
       
       foreach ($params as $p) {
        if($p->attribute == 'NAME') {
         $ret[$x]['name'] = $p->value;
         break;
    	}
       }
      }
     }
     return $ret;
    }
    
    function get_attachments($arr) {
     for($x=0; $x < sizeof($arr); $x++) {
      if($arr[$x]['disposition'] == 'attachment') {
       $ret[] = $arr[$x];
      }
     }
     return $ret;
    }
    
    $count = @imap_num_msg($inbox) or die('No Messages in mailbox!');
    //echo 'count: ' . $count;
    
    // get message headers and structure
    for ($c = 1; $c <= $count; $c++) {
     $id = $c;
     $headers = imap_header($inbox, $id);
     $structure = imap_fetchstructure($inbox, $id);
    
    // if multipart, parse
     if(sizeof($structure->parts) > 1) {
      $sections = parse($structure);
      $attachments = get_attachments($sections);
     }
    
    if ($cfg['debug']) {
     echo 'Structure of message: ' . $id . '<BR><pre>';
     print_r($structure);
     echo '</pre><BR>';
     echo 'Sections of message: ' . $id . '<BR><pre>';
     print_r($sections);
     echo '</pre><BR>';
    }
    
    // look for specified part
     for($x=0; $x<sizeof($sections); $x++) {
      if($sections[$x]['pid'] == $pid) {
        $dtype = $sections[$x]['type'];
        $dencoding = $sections[$x]['encoding'];
        $filename = $sections[$x]['name'];
      }
     }
    
    if ($cfg['debug']) {
     echo ' type: ' . $dtype . '<BR>';
     echo 'encoding: ' . $dencoding . '<BR>';
     echo 'filename: ' . $filename . '<BR>';
     echo ' id: ' . $id . '<BR><BR>';
    }
    
    $attachment = imap_fetchbody($inbox, $id, $pid);
    
    if (!$cfg['debug']) {
    
     //if (in_array(substr($filename, -4), $cfg['accepted'])) {
      if ($dencoding == 'base64') {
      // Decode and save attachment to a file
       list($usec, $sec) = explode(' ', microtime());
       $usec = substr($usec,2,3);
       $name = date('Ymd.His');
       $fp=fopen($cfg['upload_dir'].'/'.$name.'_'.$filename,'w');
       fwrite($fp,imap_base64($attachment));
       fclose($fp);
      }
     //}
    }
    
    }
    
    if (!$cfg['debug']) {
    // delete all emails
    for ($i = 1; $i <= $count; $i++) {
    imap_delete($inbox, $i);
    }
    imap_expunge($inbox);
    }
    
    imap_close($inbox);
    
    if (!$cfg['debug']) {
    header('Location: '.$cfg['upload_dir']);
    }
    ?>
    Remember that you need to access the file test/index.php in order for it to work. Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  8. #28
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    got it to work i cannot believe it haha

    finally. I thank you so much for all your help your the best.

    need anything let me know maybe i can be of some help to you!!!!

  9. #29
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Glad to hear it is working for you, let me know if you need anything else.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  10. #30
    Join Date
    Sep 2007
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    haha just one last questino.

    can i run a cron job that will execute the index.php say every 1 min?

    is that what a cron job does?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •