473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

copy Attachement from Email on server (files copied are not valid)

Hi,
I'm getting emails from an address trough a script and I want to copy the
attached files on the server. I can get the files and copy them on the
server (trough the function below) BUT the files are not valid (images
cannot be displayed)

how can I solve this?

------------------------------------------
function get_attachments($mbox,$msgno){

$o = imap_fetchstructure($mbox, $msgno);
$dir = "C:/AppServ/www/getinfo/fileadmin/testmail/"; // TEST

if ($o->type == 1 || ($o->ifsubtype == 1 && $o->subtype == 'MIXED')) {

$parts = $o->parts;
$i=1;
$retour = array();
foreach($parts as $part) {
$fname = '';

if (!isset($part->encoding) && $part->encoding == 3) {
$str = imap_base64(trim(@imap_fetchbody($mbox, $msgno,$i)));
} else {
$str = imap_fetchbody($mbox, $msgno,$i);
}
if ($part->ifdparameters == 1) {
$dparams = $part->dparameters;
foreach($dparams as $dparam) {
if ($dparam->attribute == "FILENAME") {
$fname = $dparam->value;
}
}
}
if ($fname=="") {
if ($part->ifparameters == 1) {
$params = $part->parameters;
foreach($params as $param) {
if ($param->attribute == "NAME") {
$fname = $param->value;
}
}
}
}
if ($fname=="") {$fname = "part$i";}

$fp = fopen($dir.$fname,"wb");
if (!$fp) { return FALSE; }
fwrite($fp,$str);
fclose($fp);
$i++;
}
return $retour;
} else {
return "no attach";
}
}
Jul 16 '05 #1
1 1695
"nic den" <nd******@yahoo.fr> wrote in message
news:3f********@news.swissonline.ch...
Hi,
I'm getting emails from an address trough a script and I want to copy the
attached files on the server. I can get the files and copy them on the
server (trough the function below) BUT the files are not valid (images
cannot be displayed)

how can I solve this?

<snip users untested code>

Aren't e-mail attachments Base64 encoded?
Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: b.milbrandt | last post by:
I am trying to convert a unix shell script to perl, and I have having a problem with the portion that copies files based on extension and renaming them in the process. I only trying to copy files...
9
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that...
5
by: kebuchan | last post by:
Hi all, I know this is possible in Oracle but has anyone done it in DB2 and could you maybe direct me to some documentation or let me know how I would go about doing it? In the oracle world...
9
by: fniles | last post by:
I would like to copy a table(s) from SQL Server 2005 to a CVS file and vice versa. I was thinking to use the BCP command line utility, but I have a few questions: 1. The machine where I am...
1
by: ll | last post by:
Hi, I have copied a MS SQL database to my local machine and am testing it with ASP pages, locally, on IIS. I have a db connect page that keeps the current connections for the live database. My...
2
by: Jeff | last post by:
....hope this question is on the right ng. The code below works to copy all files and folders from D:\Template to a new location that is specified by the user. Is there any easy way to modify...
1
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
Using .NET 2.0 is it more efficient to copy files to a single folder versus spreading them across multiple folders. For instance if we have 100,000 files to be copied, Do we copy all of them to...
3
by: Ken Fine | last post by:
Hi, I'm using the VS.NET 2008 website copy tool. It is supposed to keep track of whether files are new, changed, or unchanged relative to a site on my "remote" server. Most of the time it does...
7
by: Arthur | last post by:
hi, this might be a simple one to them who know: i'm developing an asp.net project and use the debug mode. i have a xml file which contains data, that shall be read, if a specific page is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.