Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL: from PHP to BASH

I've never done any curl before so am in need of some help.

php:

<?php
$ch = curl_init();

$data = array(
        'uptype'=>'file',
        'file'=>'@'.$argv[1],
);

curl_setopt($ch, CURLOPT_URL, 'http://my_site_ex/up.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);
curl_close($ch);
?>

how to make the same script in BASH?

like image 567
flienteen Avatar asked May 30 '10 14:05

flienteen


1 Answers

I believe it's:

curl -F "uptype=file" -F "file=@$1" 'http://my_site_ex/up.php'

The -F uses multipart/form-data, which the PHP interface libcurl uses if you pass an array for CURLOPT_POSTFIELDS. Each -F is a separate field. libcurl reads the file you specify with @.

like image 129
Matthew Flaschen Avatar answered Oct 01 '22 01:10

Matthew Flaschen