通过bash中的curl上传文件 [英] file upload via curl in bash

查看:132
本文介绍了通过bash中的curl上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过curl直接在我的网站上的POST字段中上传文件,而不是在php中使用curl?在php中,您可以执行以下操作:

How can I upload a file in a POST field on my website via curl directly rather using curl in php? In php you can do this with:

<?
$fileupload="image.jpg";
$c = curl_init("file");
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS,
array('Filedata'=>"@$fileupload",'folder'=>'/target/'));
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_exec($c);
curl_close($c);
?>

但是如何在带有curl的Linux bash脚本中完成此操作?

but how can this be done in a linux bash script with curl?

推荐答案

作为哈希数组发送的CURLOPT_POSTFIELDS选项成为一系列-F用法.与此类似:

The CURLOPT_POSTFIELDS option sent as a hash array becomes a series of -F uses. Something similar to this:

curl -F Filedata=@image.jpg -F folder=/target/ [URL]

这篇关于通过bash中的curl上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆