/    Sign up×
Community /Pin to ProfileBookmark

Attach image to email without saving to disk

Does anyone know of a way to attach jpg image created in php without having to save the file to the server before attaching it?

I am using this MIME code to attach the image to an email –

[code=php]
for($i=0;$i<$max;$i++)
{
$file = fread(fopen($this->attachment[$i], “r”), filesize($this->attachment[$i]));
$this->header .= “–“.$this->boundary.”n”;
$this->header .= “Content-Type: application/x-zip-compressed; name=”.$this->attachment[$i].”n”;
$this->header .= “Content-Transfer-Encoding: base64n”;
$this->header .= “Content-Disposition: attachment; filename=”.$this->attachment[$i].”nn”;
$this->header .= chunk_split(base64_encode($file)).”n”;
$file = “”;
}
[/code]

Can I attach the image stored as a variable for instance?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehMay 15.2007 — Where is the code that is producing the image?
Copy linkTweet thisAlerts:
@heals1icauthorMay 16.2007 — [code=php]
$im = imagecreatefromjpeg($img)
[/code]


where $img is the path to an existing image.

What I am doing is using a default image on the server and allowing the user to add text to it and then email it.

Every user will use the same default image.
Copy linkTweet thisAlerts:
@bokehMay 17.2007 — Just capture the image to a string:
[code=php]ob_start();
imagejpeg($image);
$image_as_string = ob_get_clean();[/code]
Now just base 64 encode it and attach it to the email.
×

Success!

Help @heals1ic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...