# Converting to binary

**URL:** <https://forum.kirupa.com/t/converting-to-binary/326702>\
**Category:** programming\
**Created:** [January 6, 2012, 5:02am UTC](https://forum.kirupa.com/t/converting-to-binary/326702 "2012-01-06T05:02:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![holysocks](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@holysocks](https://forum.kirupa.com/u/holysocks)\
**Post date:** [January 6, 2012, 5:02am UTC](https://forum.kirupa.com/t/converting-to-binary/326702/1 "2012-01-06T05:02:19Z")

</div>

Hi  
I have this piece of PHP code that takes data from Flash and then sends an email with an image attachment using SwiftMailer.

```php
<?ph
prequire_once 'lib/swift_required.php';
$image = $_GET['pic'];
$sendto = $_GET['to'];
$sendarray = explode(' ',$sendto);

$attachment = Swift_Attachment::newInstance($image, 'submission.jpg', 'image/jpg');
$message = Swift_Message::newInstance();
$message->setSubject('Do you hear me now');
$message->setFrom(array('donotreply@mydomain.com'));
$message->setBody("Here is your picture!");
for($i=0;$i<count($sendarray);$i++){
    $message->addTo($sendarray[$i]);
}
$message->attach($attachment);

$transport = Swift_SendmailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
 $mailer->send($message);
?>

```

I’ve tested it and everything works EXCEPT the image attachment part. I’m sure that $image needs to be in binary, but I do not know how. When I send it from Flash, it is a ByteArray, but I still need to convert to binary in PHP. Can someone help?  
Thanks in advance.
