CURL: from PHP to BASH

I never made an occasion before I needed 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?

+5
source share
2 answers

I believe this:

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

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

+5
source

I believe so

data='-F "uptype=file" F "file=@$1"'
server="http://my_site_ex:8080/up.php"
opts="-v"

curl $server $opts $data

Im not 100% unfortunately, but something like that.

0
source

All Articles