The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

post files and parameters in curl command line for testing

Eyal's Avatar

Eyal

18 Jul, 2012 04:53 PM

how can i post files and parameters in curl command line for testing ?

  1. Support Staff 1 Posted by Brian Nesbitt on 23 Jul, 2012 01:44 AM

    Brian Nesbitt's Avatar

    I am on windows but using a port of curl 7.21.1 the following worked for me.

    I have a PHP 5.4 dev server running locally on port 80 and an image.jpg file to upload in the current directory where I ran `curl.

    curl command line:

    curl --form uploadfile=@image.jpg --form username=brian --form email=[email blocked] http://127.0.0.1/savefile/12345
    

    Slim route reading variables from the URI, POSTed form and uploaded file:

    $app->post('/savefile/:id', function ($id) use($app) {
        printf("Id       = %d\n", $id);
        printf("Username = %s\n", $app->request()->params("username"));
        printf("Email    = %s\n", $app->request()->params("email"));
        if (isset($_FILES['uploadfile'])) {
            printf("Uploaded = [%s] [%d]\n", $_FILES['uploadfile']['name'], $_FILES['uploadfile']['size']);
        }
    });
    

    and the associated output from curl:

    Id       = 12345
    Username = brian
    Email    = [email blocked]
    Uploaded = [image.jpg] [1719420]
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? 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