Using curl to upload POST data with files
https://stackoverflow.com/questions/12667797/using-curl-to-upload-post-data-with-files
************************************************************************
I would like to use cURL to not only send data parameters in HTTP POST but to also upload files with specific form name. How should I go about doing that ?
HTTP Post parameters:
userid = 12345 filecomment = This is an image file
HTTP File upload: File location = /home/user1/Desktop/test.jpg Form name for file = image (correspond to the $_FILES['image'] at the PHP side)
I figured part of the cURL command as follows:
curl -d "userid=1&filecomment=This is an image file" --data-binary @"/home/user1/Desktop/test.jpg" localhost/uploader.php
The problem I am getting is as follows:
Notice: Undefined index: image in /var/www/uploader.php
The problem is I am using $_FILES['image'] to pick up files in the PHP script.
How do I adjust my cURL commands accordingly ?
=============
You need to use the -F
option:
-F/--form <name=content> Specify HTTP multipart POST data (H)
try this
curl \
-F "userid=1" \
-F "filecomment=This is an image file" \
-F "image=@/home/user1/Desktop/test.jpg" \
localhost/uploader.php
=======================
Catching the user id as path variable (recommended):
curl -i -X POST -H "Content-Type: multipart/form-data"
-F "data=@test.mp3" http://mysuperserver/media/1234/upload/
Catching the user id as part of the form:
curl -i -X POST -H "Content-Type: multipart/form-data"
-F "data=@test.mp3;userid=1234" http://mysuperserver/media/upload/
=========================
....................................
Using curl to upload POST data with files的更多相关文章
- [Python] 05 - Load data from Files
文件读写 一.文件打开 传统方法 >>> f = open('data.txt', 'w') # Make a new file in output mode ('w' is wri ...
- [Android Tips] 10. Pull out /data/data/${package_name} files without root access
#!/usr/bin/env bash PACKAGE_NAME=com.your.package DB_NAME=data.db rm -rf ${DB_NAME} adb shell " ...
- Android下/data/data/<package_name>/files读写权限
今天将更新模块拿到android上面测试的时候,发现在创建writablepath.."upd/"目录的时候出现Permission Denied提示BTW:我使用的是lfs来创建 ...
- 微信公众号获取用户openId How to use cURL to get jSON data and decode the data?
w http://stackoverflow.com/questions/16700960/how-to-use-curl-to-get-json-data-and-decode-the-data
- AnyImgUpload
@{ ViewBag.Title = "ImgForAny"; Layout = null; } <h2>ImgForAny</h2> <script ...
- ASP.NET简单实现APP中用户个人头像上传和裁剪
最近有个微信项目的用户个人中心模块中,客户要求用户头像不仅仅只是上传图片,还需要能对图片进行裁剪.考虑到flash在IOS和Android上的兼容性问题,于是想着能从js这块入手,在网上发现了devo ...
- 适应各浏览器图片裁剪无刷新上传jQuery插件(转)
看到一篇兼容性很强的图片无刷新裁剪上传的帖子,感觉很棒.分享下!~ 废话不多说,上效果图. 一.首先建立如下的一个page <!DOCTYPE html> <html xmlns=& ...
- 适用于各浏览器支持图片预览,无刷新异步上传js插件
文件上传无疑是web应用中一个非常常用的功能,不管是PHP.jsp还是aspx.mvc等都会需要文件上传,但是众所周知当使用自带的文件上传功能时总会出现页面刷新的情况.当然现在有了html5这个好东西 ...
- Upload Files In ASP.NET Core 1.0 (Form POST And JQuery Ajax)
Uploading files is a common requirement in web applications. In ASP.NET Core 1.0 uploading files and ...
随机推荐
- warning C4005 DXGI_STATUS_OCCLUDED
注意包含顺序 要将 $(DXSDK_DIR)Include放在后面才行 $(VC_IncludePath)$(WindowsSDK_IncludePath)$(DXSDK_DIR)Include 为了 ...
- [Spring学习笔记 7 ] Spring中的数据库支持 RowMapper,JdbcDaoSupport 和 事务处理Transaction
1.Spring中的数据库支持 把具有相同功能的代码模板抽取到一个工具类中.2.关于jdbc template的应用 jdbcTemplate模板操作类,把访问jdbc的模板抽取到template中, ...
- jQuery.ajax发送image请求格式
1\请求端 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head run ...
- SQL plan directives
SQL plan directives SQL plan directives含有优化器产生优化的执行计划时需要的附加信息和指令. 在sql执行时,如果cardinality估计有错误,数据库就会创建 ...
- 企业内知识库wiki所存在的问题
相信很多公司都利用开源的wiki web app搭建了自家的内部wiki服务,比如使用media Wiki, Gollum, doku wiki, jsWiki等 但是,真正可用的企业wiki系统却没 ...
- JPA学习笔记(8)——映射一对多关联关系
一对多关联关系 本文有很多和多对一是一样的,因此不会写得非常具体. 有看不懂的.能够參考JPA学习笔记(7)--映射多对一关联关系 Order实体类 package com.jpa.helloworl ...
- 温故而知新 phpstudy 设置 nginx 代理
nginx.conif 找到 server 关键字配置 server { listen ; server_name localhost; #charset koi8-r; #access_log lo ...
- mysql查询今天、昨天、本周、本月、上一月 、今年数据
mysql数据库中的关于查询日期的一些操作如下: --今天 select * from 表名 where to_days(时间字段名) = to_days(now()); --昨天 --本周 SELE ...
- 硬盘内部硬件结构和工作原理详解[zz]
一般硬盘正面贴有产品标签,主要包括厂家信息和产品信息,如商标.型号.序列号.生产日期.容量.参数和主从设置方法等.这些信息是正确使用硬盘的基本依据,下面将逐步介绍它们的含义. 硬盘主要由盘体.控制电路 ...
- RocketMQ最佳实践(一)4.0版本/概念介绍/安装调试/客户端demo
为什么选择RocketMQ 我们来看看官方回答: “我们研究发现,对于ActiveMQ而言,随着越来越多的使用queues和topics,其IO成为了瓶颈.某些情况下,消费者缓慢(消费能力不足)还会拖 ...