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的更多相关文章

  1. [Python] 05 - Load data from Files

    文件读写 一.文件打开 传统方法 >>> f = open('data.txt', 'w') # Make a new file in output mode ('w' is wri ...

  2. [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 " ...

  3. Android下/data/data/<package_name>/files读写权限

    今天将更新模块拿到android上面测试的时候,发现在创建writablepath.."upd/"目录的时候出现Permission Denied提示BTW:我使用的是lfs来创建 ...

  4. 微信公众号获取用户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

  5. AnyImgUpload

    @{ ViewBag.Title = "ImgForAny"; Layout = null; } <h2>ImgForAny</h2> <script ...

  6. ASP.NET简单实现APP中用户个人头像上传和裁剪

    最近有个微信项目的用户个人中心模块中,客户要求用户头像不仅仅只是上传图片,还需要能对图片进行裁剪.考虑到flash在IOS和Android上的兼容性问题,于是想着能从js这块入手,在网上发现了devo ...

  7. 适应各浏览器图片裁剪无刷新上传jQuery插件(转)

    看到一篇兼容性很强的图片无刷新裁剪上传的帖子,感觉很棒.分享下!~ 废话不多说,上效果图. 一.首先建立如下的一个page <!DOCTYPE html> <html xmlns=& ...

  8. 适用于各浏览器支持图片预览,无刷新异步上传js插件

    文件上传无疑是web应用中一个非常常用的功能,不管是PHP.jsp还是aspx.mvc等都会需要文件上传,但是众所周知当使用自带的文件上传功能时总会出现页面刷新的情况.当然现在有了html5这个好东西 ...

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

随机推荐

  1. linux 的时区设置函数tzset() 【转】

    linux 的时区设置函数tzset() 本文转载于: http://blog.csdn.net/epicyong333/article/details/5258152 tzset #incude & ...

  2. 入门程序,hello world

    RabbitMQ是消息代理.从本质上说,它接受来自生产者的信息,并将它们传递给消费者.在两者之间,它可以根据你给它的路由,缓冲规则进行传递消息. 一.专业术语 1. 生产者: 在现实生活中就好比制造商 ...

  3. Zabbix Trigger表达式实例

    Zabbix提供强大的触发器(Trigger)函数以方便进行更为灵活的报警及后续动作,具体触发器函数可以访问https://www.zabbix.com/documentation/2.0/manua ...

  4. springboot(五):spring data jpa的使用

    在上篇文章springboot(二):web综合开发中简单介绍了一下spring data jpa的基础性使用,这篇文章将更加全面的介绍spring data jpa 常见用法以及注意事项 使用spr ...

  5. shell小工具查看Hadoop中System.out输出的日志

    #!/bin/bashrm ~/log.logecho "Please Input JobID:"read NAMEmap_log="/home/grid/hadoop- ...

  6. GIF Brewery for Mac(录制 Gif 动图工具)安装

    1.软件简介    GIF Brewery 一款用于录制 Gif 动图等的工具. 2.资源列表 链接 提取密码 系统要求 软件语言 GIF Brewery for Mac v3.9.5 ltmf ma ...

  7. golang 学习 ---- channel

    把一个loop放在一个goroutine里跑,我们可以使用关键字go来定义并启动一个goroutine: package main import "fmt" func loop() ...

  8. 【转载并整理】JAVA解析或生成xml的四种方法

    参考文章 1:http://blog.csdn.net/clemontine/article/details/53011362 2:http://www.jb51.net/article/98456. ...

  9. win10 docker 安装部署

    Docker 安装教程: https://blog.csdn.net/hunan961/article/details/79484098 安装docker前需要首先开启虚拟服务:重启电脑-->F ...

  10. dd-wrt 中继配置

    本配置方法在tp-link 703n v1.6上应用成功 1.首先把703n刷成dd-wrt.这里我刷的是 DD-WRT v24-sp2 (03/15/12) std版本,要刷两个固件,一个facto ...