My company has an html form to send variables and update image (jpeg) to the server, I tried to automate it using curl, but got stuck. I can send variables but not the image.
I used "tamper data" firefox and noticed that my form send the following variables to the server:
-----------------------------291231848620019\r\nContent-Disposition: form-data; name="pin"\r\n\r\ndf8794b1ec63c7094f6498f7a1322bcc\r\n-----------------------------291231848620019\r\nContent-Disposition: form-data; name="yourdata"\r\n\r\nonly test\r\n-----------------------------291231848620019\r\nContent-Disposition: form-data; name="your_file"; filename="chansy.jpg"\r\nContent-Type: image/jpeg\r\n\r\n{content-of-image-file-here}\r\n-----------------------------291231848620019\r\nContent-Disposition: form-data; name="birth_date[]"\r\n\r\n1\r\n-----------------------------291231848620019\r\nContent-Disposition: form-data; name="birth_date[]"\r\n\r\n1\r\n-----------------------------291231848620019\r\nContent-Disposition: form-data; name="birth_date[]"\r\n\r\n1970\r\n-----------------------------291231848620019\r\nContent-Disposition: form-data; name="your_email"\r\n\r\nkrunker@asia.com\r\n-----------------------------291231848620019\r\nContent-Disposition: form-data; name="code"\r\n\r\n\r\n-----------------------------291231848620019\r\nContent-Disposition: form-data; name="pass"\r\n\r\npass_sample\r\n-----------------------------291231848620019\r\nContent-Disposition: form-data; name="act"\r\n\r\nUpdate Changes\r\n-----------------------------291231848620019\r\nContent-Disposition: form-data; name="your_name"\r\n\r\njust me\r\n-----------------------------291231848620019--\r\n
here is the code i used on array postfields:
$img=file_get_contents($filename);
$data = array('pin' => $pin, 'yourdata' => $_POST['yourdata'], 'your_file'=>$img, 'filename' =>$filename, 'Content-Type' => 'image/jpeg', 'birth_date[]' => $_POST['birth_date'], 'birth_date[]' => $_POST['birth_month'], 'birth_date[]' => $_POST['birth_year'], 'your_email' => $_POST['your_email'], 'pass' => $_POST['pass'], 'act' => 'Update changes', 'your_name' => $_POST['your_name']);
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch , CURL_HTTPHEADER , "Content-Type: multipart/form-data" );
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_REFERER, "http://internalweb.com/");
curl_setopt($ch, CURLOPT_URL, "http://internalweb.com/profile");
$page = curl_exec($ch);
On the result, when I run my script, it can update those variables, but no luck with the image.. i am so confuse... what should i do to put in variable?
I am learning everything from google, and now i am stuck since i dont have any knowledge in deep programming, can you please help me what to do to put image in $data array?
I tried to look on the thread of:
multipart/form-data into array not processing
multipart/form-data php curl
Posting raw image data as multipart/form-data in curl
note:
I tried to follow Hassan's suggestion, but not work still. Does anyone know how to convert this:
Content-Disposition: form-data; name="your_file"; filename="merc.jpg"
Content-Type: image/jpeg
$contentfile
into $data array for curl?