<?php
$actionUrl = 'http://server/upload/jup.jsp';
$post_params['title'] = 'How to upload auto by cURL and PHP';
$post_params['tag'] = 'curl, php, auto, upload, submit, form, http, post';
# File will be upload
# First
$post_params['ufile'] = '@/home/huypv/private/xxx.txt;text/plain';
/*
——WebXXXFormBoundaryjmXSvBkBa2nO7Z3j
Content-Disposition: form-data; name="ufile"; filename="xxx.txt"
Content-Type: text/plain
CONTENT OF FILE xxx.txt
*/
# And more
$post_params['ifile'] = '@/home/huypv/private/yyy';
/*
——WebXXXFormBoundaryjmXSvBkBa2nO7Z3j
Content-Disposition: form-data; name="ifile"; filename="yyy"
Content-Type: application/octet-stream
CONTENT OF FILE yyy
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $actionUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
#curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
$result = curl_exec($ch);
#var_dump( curl_getinfo($ch, CURLINFO_HEADER_OUT));
curl_close($ch);
Server
<form action="http://server/upload/jup.jsp" method="post" enctype="multipart/form-data">
<input type="text" name="title" /><br />
<input type="text" name="tag" /><br />
<input type="file" name="ufile" /><br />
<input type="file" name="ifile" /><br />
<input type="submit" value="Post" />
</form>