zoukankan      html  css  js  c++  java
  • 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/

    =========================

    ....................................

  • 相关阅读:
    [轉]Discuz!NT 数据库读写分离方案
    [轉]最流行的PHP MVC框架
    [轉]关于MS SQL的执行计划
    [轉]Oracle读写分离架构
    [轉]資料庫讀寫分離
    [轉]SQL Server 老是死锁,或提示进程已牺牲,怎麽解决
    [轉]让IIS支持解析json
    [轉]jquery.validate全攻略
    [轉]Flex判断对象的类型
    [轉]mssql 数据表修复方法
  • 原文地址:https://www.cnblogs.com/zhao1949/p/7550391.html
Copyright © 2011-2022 走看看