posting file “multipart/form-data” through php

trancers21

New Member
Im trying to use imageshshack api in phpin the following way:\[code\]<?phpfunction do_post_request($url, $data, $optional_headers = null) { $params = array('http' => array( 'method' => 'POST', 'content' => $data )); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen($url, 'rb', false, $ctx); if (!$fp) { throw new Exception("Problem with $url, $php_errormsg"); } $response = @stream_get_contents($fp); if ($response === false) { throw new Exception("Problem reading data from $url, $php_errormsg"); } return $response;} $fileName = $_FILES['picture']['name']; $tmpName = $_FILES['picture']['tmp_name']; $fileSize = $_FILES['picture']['size']; $fileType = $_FILES['picture']['type']; $fo = @fopen($tmpName, "r"); $imgposted = @fread($fo, filesize($tmpName)); $imgposted = addslashes($imgposted); $data = 'http://stackoverflow.com/questions/3663373/fileupload='.$imgposted.'&rembar=1&key=******'; echo do_post_request('http://www.imageshack.us/upload_api.php',$data);?>\[/code\]but the data is being posted normally, I wanted to be posted like if I had a form with this attribute:\[code\]enctype="multipart/form-data"\[/code\]any solution?
 
Back
Top