6

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?

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.