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 "https://www.example.com/upload.php" -F myfile=@"/path/to/file"

Example:

$ curl "https://www.example.com/upload.php" -F myfile=@"~/Desktop/image.png"

And using authentication:

$ curl -u username:password "https://www.example.com/upload.php" -F myfile=@"~/Desktop/image.png"

NOTE: Change myfile to the file input value name.

<input name="myfile" type="file" />
// upload.php
var_dump($_POST);
var_dump($_FILES);
View this page on GitHub.
Posted .

4 comments

  1. anonymous

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

    Any ideas?! Thanks!

  2. anonymous

    @array(0)

    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