How to upload a file via the command line using cURL; Upload an image using curl

To upload a file using the command line, do the following:

$ curl "" -F myfile=@"/path/to/file"


$ curl "" -F myfile=@"~/Desktop/image.png"

And using authentication:

$ curl -u username:password "" -F myfile=@"~/Desktop/image.png"

NOTE: Change myfile to the file input value name.

<input name="myfile" type="file" />
// upload.php
This post is available on GitHub.
Posted .


  1. anonymous

    When I try this, I just get the message: array(0)

    Any ideas?! Thanks!

  2. anonymous


    try var_dump($_POST) and var_dump($_GET); to see if at least something is coming through

  3. anonymous

    Thanks :) .. it helped.

  4. anonymous

    was about to pull my hair out. Stumbled upon your page. Works perfectly.

Leave a Reply