The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Working with binary data?

titusblair's Avatar


13 Apr, 2012 05:45 AM

First off Slim is awesome! Thanks for making it available!
I was wondering how I could work with Binary data for example sending images with a post? Any examples would be much appreciated.
For example sending photos, etc. from an iPhone or Android device.

  1. Support Staff 1 Posted by Josh Lockhart on 13 Apr, 2012 12:16 PM

    Josh Lockhart's Avatar

    Hi Titus,

    I'm glad you are enjoying Slim. Currently, Slim does not provide helper methods to help with POSTed binary or multipart data. For now, you'll need to continue using the $_FILES superglobal to access uploaded data.


  2. 2 Posted by titusblair on 13 Apr, 2012 07:59 PM

    titusblair's Avatar

    Hey Josh,
    Thanks for the post.
    Would you be able to put a snippet of code to handle a binary submit? I am having difficulty on this one.
    Really appreciate it!

  3. Support Staff 3 Posted by Josh Lockhart on 13 Apr, 2012 08:05 PM

    Josh Lockhart's Avatar

    I'm assuming your uploading data from an HTML form. This is the markup:

    <form action="/submit-handler.php" method="post" enctype="multipart/form-data">
        <input type="file" name="upload" value=""/>
        <input type="submit" value="Upload Now"/>

    And in your PHP script, you'd reference $_FILES like this:

    if ( is_uploaded_file($_FILES['upload']['tmp_name']) ) {
        move_uploaded_file($_FILES['upload']['tmp_name'], '/path/to/destination/file.ext');

    Make sense? It's basically what you'd do to handle a normal file upload without Slim.


  4. 4 Posted by titusblair on 13 Apr, 2012 08:28 PM

    titusblair's Avatar

    Hey Josh,
    I am using AJAX in the background to submit the page data, do you think it
    has to do with the ajax not posting the binary data?
    Thanks so much for the quick response!

  5. Support Staff 5 Posted by Josh Lockhart on 13 Apr, 2012 08:30 PM

    Josh Lockhart's Avatar

    I'd use an HTTP inspector to review the HTTP request that is being sent and make sure that the request content-type is set appropriately and its body seems appropriate.

  6. 6 Posted by titusblair on 13 Apr, 2012 08:47 PM

    titusblair's Avatar

    Thanks Josh appreciate it!!

  7. Andrew Smith closed this discussion on 01 Aug, 2012 12:53 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac