Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Upload images via e-mail

Posted on 2009-07-11
8
Medium Priority
?
249 Views
Last Modified: 2013-12-25
Hello,

I'm trying to write a dead-simple PHP script that would allow me to e-mail an image (as an attachment) to an e-mail address on my server (e.g. uploadimages@myserver.com) and then have the script upload/save the picture to my server.

How could I do it (or, alternatively, where can I find a dead-simple PHP script that already does this)?

Thanks.
0
Comment
Question by:NeedExpertHelp
  • 3
  • 3
  • 2
8 Comments
 

Expert Comment

by:msaqibansari
ID: 24830011
0
 

Author Comment

by:NeedExpertHelp
ID: 24830041
Thanks for your reply.

What's a PIPE script?
0
 

Expert Comment

by:msaqibansari
ID: 24830270
PIPE script is a server-side script written in your favorite language like PHP that read email content and parse image header and content and write it hard disk.

If you're using CPanel then there is an option to forward email to PIPE script e.g.
http://kb.siteground.com/article/How_to_pipe_an_email_to_a_PHP_script.html

If you're working on Linux environment do the following steps.

Step 1. create a new email address e.g. uploadimages@mydomain.com
Step 2. Forward emails to your script written to handle email content e.g. /home/myusr/pipe.php
Step 3. Pipe.php is your file that parse image content from email.

Following URL have briefly describe this process.
http://activecampaign.com/support/tt/index.php?action=kb&article=145

Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:NeedExpertHelp
ID: 24830371
Thanks again for the additional info.

I will give it a try via cPanel and report back.

Where can I download the PIPE script in PHP?

Thanks.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24831265
The "dead-simple" part is going to be the issue.  It will not be dead-simple once you have email involved in the process.  So please help me understand something more about your requirement...  

If you have an image on a client computer that is capable of handling email, would you not also expect the client computer to he able to handle HTTP protocols?  And it follows that if you can use HTTP, you can use HTTP to access an image upload script on the server, right?  So what is the advantage of attaching the image to an email message, when you can simply upload it to the server with a file-upload script?

Thanks and regards, ~Ray
0
 

Author Comment

by:NeedExpertHelp
ID: 24831282
Ray, the answer is as simple as the script I'm looking for:  not all cell phones are compatible with type="file" uploads.

Any word on where I might find the PIPE script?
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 24831712
OK, that makes sense.  Flickr can do this sort of upload via email.  Each Flickr client has a unique email address so the pictures do not get mixed up.  Various combinations of info in the subject line can be used to identify the photos that are sent to Flickr via email.

A sample PIPE script is contained in this link:
http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914/

It appears that all you need to do is set up your "pipe" with a destination script.  The destination script reads from stdin.  Then the fun begins.  What do you do with the input that comes through the pipe??

A similar question and answer is here, however I have not evaluated the quality of the answer:
http://stackoverflow.com/questions/114953/how-to-get-email-and-their-attachments-from-php

And these look interesting:
http://www.phpclasses.org/browse/package/3169.html
http://www.hotscripts.com/listing/email-mime-parser-decoder-in-php/
http://www.bucabay.com/2009/web-development/incoming-mail-php-mime-mail-parser/

Best of luck with it, ~Ray
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 25335102
Since you asked this question, I have had occasion to set up a PIPE script of my own.  Here are the essential moving parts.  HTH, ~Ray
#!/usr/bin/php -q
<?php // /email_pipe/index.php
 
// THIS IS AN EMAIL PIPE SCRIPT.
// THIS SCRIPT IS STARTED AUTOMATICALLY FOR EACH MESSAGE.
// NOTE THAT THIS SCRIPT IS ABOVE THE /public_html/ DIRECTORY TO PREVENT ACCIDENTAL EXECUTION
//
// --> HOW DO WE KNOW WHICH EMAIL MESSAGES GET SENT HERE?
// THIS SCRIPT RECEIVES MESSAGES SENT TO email_pipe@your.org
// CREATE AN EMAIL MAILBOX EXCLUSIVELY FOR AUTOMATED PROCESSING.
// SET UP AN EMAIL FORWARD FOR THAT MAILBOX IN cPANEL->EMAIL LIKE THIS:
// 1...5...10...15...20...25...
// |/home/{account}/email_pipe/index.php
//
// --> WHEN YOU UPLOAD, THIS SCRIPT WILL BE MARKED RW-R-R BUT THAT IS WRONG
// THIS SCRIPT MUST BE MARKED EXECUTABLE x0755
// YOU CAN USE FTP SOFTWARE TO CHMOD TO RWX-RX-RX
//
// --> NOTE THE FIRST LINE OF THIS SCRIPT MUST SAY #!/usr/bin/php -q STARTING IN COLUMN ONE
// 1...5...10...15...20...25...
// #!/usr/bin/php -q
// <?php ... PROGRAM CODE FOLLOWS
 
$script_start_time = microtime(TRUE);
error_reporting(E_ALL);
ob_start();
 
// DATA BASE CONNECTIVITY, CONSTANTS, FUNCTIONS, ETC
require_once('config.php');
 
// TRY TO READ THE EMAIL FROM STDIN
if (!$stdin = fopen("php://stdin", "R"))
{
    echo "ERROR: UNABLE TO OPEN php://stdin \n";
    die();
}
 
// ABLE TO READ THE MAIL
else
{
    $raw_email = '';
    while (!feof($stdin))
    {
        $raw_email .= fread($stdin, 4096);
    }
    fclose($stdin);
}
$raw_email = preg_replace('| +|', ' ', $raw_email);
 
// ETC ETC...

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

824 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