views:

59

answers:

2

Hi.. 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?

+3  A: 

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

Matthew Flaschen
thanks it works ^_^
flienteen
A: 

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.

RobertPitt
You can't have spaces around the equal sign in Bash.
Dennis Williamson
yup i just typed it up, been working on PHP lately that's why :/ my bad
RobertPitt