开发者

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($c开发者_StackOverflow社区h, 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?


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 @.


I belive its like 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 its something along these lines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜