Hi Im trying to automate the upload of pictures to imgbay... seeing the request that is generated from the browser with wireshark and seeing this post I came up with this.
$destination = "http://bayimg.com";
$eol = "
";
$data = '';
$str=file_get_contents('umbered1.jpg');
$mime_boundary='-------------------------'. time();
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="file;"';
$data .= 'filename="umbered1.jpg"' . $eol;
$data .= 'Content-Type: image/jpeg' . $eol . $eol;
$data .= $str. $eol;
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Disposition: form-data; name="code"' . $eol;
$data .= 'bla';
$data .= '--' . $mime_boundary . $eol;
$data .= 'Content-Type: form-data; name="tags"' . $eol;
$data .= '--' .$mime_boundary . $eol.$eol;
$params = array('http' => array(
'method' => 'POST /upload',
'protocol_version' => '1.1',
'header' => 'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0'. $eol .
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'. $eol .
'Accept-Language: en-US,en;q=0.5' . $eol .
'Accept-Encoding: gzip, deflate' . $eol .
'Referer: http://bayimg.com/' . $eol .
'Content-Type: multipart/form-data; boundary='. $mime_boundary. $eol .
"Content-Length: " . strlen($data). $eol,
'content' => $data
));
$ctx = stream_context_create($params);
echo $response = @file_get_contents($destination, 0, $ctx);
what I see in wireshark is this
POST /upload / HTTP/1.1
Host: bayimg.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://bayimg.com/
Content-Type: multipart/form-data; boundary=-------------------------1409116238
Content-Length: 12681
---------------------------1409116238
Content-Disposition: form-data; name="file;"filename="umbered1.jpg"
Content-Type: image/jpeg
//Here comes the image data....
---------------------------1409116238
Content-Disposition: form-data; name="code"
bla---------------------------1409116238
Content-Type: form-data; name="tags"
---------------------------1409116238
HTTP/1.1 200 OK
Server: nginx/1.6.0
Date: Wed, 27 Aug 2014 05:10:41 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.6.0RC3
Set-Cookie: country=AR; expires=Wed, 03-Sep-2014 05:10:41 GMT; Max-Age=604800
Content-Encoding: gzip
// the response is an error page
///// end of packet
The server responds but its an error....
this is what I get when I upload the image via the web.
POST /upload HTTP/1.1
Host: bayimg.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://bayimg.com/
Cookie: country=AR; __PPU_SESSION_4-7=X54717,1408841107,0,0X
Connection: keep-alive
Content-Type: multipart/form-data; boundary=---------------------------51442902223623
Content-Length: 12721
-----------------------------51442902223623
Content-Disposition: form-data; name="file"; filename="umbered1.jpg"
Content-Type: image/jpeg
/// here comes the image data
-----------------------------51442902223623
Content-Disposition: form-data; name="code"
bla
-----------------------------51442902223623
Content-Disposition: form-data; name="tags"
-----------------------------51442902223623--
HTTP/1.1 200 OK
Server: nginx/1.6.0
Date: Wed, 27 Aug 2014 05:18:50 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.6.0RC3
Content-Encoding: gzip
// the response is a error page
I see that I am not using the Cookies but I don't know how to set them. I also tried with curl but this is the closes that i get to replicate the header... any help will be appreciated. thanks!