I need to post the contents of a file to a webpage (C#) in the form of a Byte[] from PHP. I've tried using cURL
and stream_context_create()
but what I think it comes down to is how I'm reading out the file.
My post content/CURLOPT_POSTFIELDS looks like:
$data .= "\r\n--" . $boundary . "\r\n";
$data .= "Content-Disposition: form-data; name=\"file\"; filename=\"" . $files['name'][$id] . "\"\r\n";
$data .= "Content-Type: application/octet-stream\r\n\r\n";
$data .= file_get_contents($files['tmp_name'][$id]) . "\r\n";
$data .= "--" . $boundary . "--\r\n";
But this just doesn't work.
Post byte array from PHP to .NET WCF Service says that file_get_contents()
is compatible - but I'm not finding any evidence of this.
http://bytes.com/topic/php/answers/869014-how-convert-gif-file-byte-array-thanks states this isn't possible. (Nothing is impossible!)
I've also tried using variations of fread()
fopen()
and file()
etc
PS I know the webservice is working fine as a somewhat identical script in C++/Java etc works fine. file.readAll()
being the only difference where the file_get_contents()
line is...
Grateful for any insigtfull comments or an answer to fix my woes!