【发布时间】:2011-10-12 16:21:19
【问题描述】:
我需要从 PHP 以 Byte[] 的形式将文件的内容发布到网页 (C#)。我尝试过使用cURL 和stream_context_create(),但我认为归根结底是我如何读出文件。
我的帖子内容/CURLOPT_POSTFIELDS 看起来像:
$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";
但这根本行不通。
Post byte array from PHP to .NET WCF Service 说 file_get_contents() 是兼容的 - 但我没有找到任何证据。
http://bytes.com/topic/php/answers/869014-how-convert-gif-file-byte-array-thanks 表示这是不可能的。 (没有什么是不可能的!)
我也尝试过使用 fread() fopen() 和 file() 等的变体
PS 我知道 Web 服务运行良好,因为 C++/Java 等中的一个有点相同的脚本运行良好。 file.readAll() 是 file_get_contents() 行的唯一区别...
感谢任何 insigtfull cmets 或解决我问题的答案!
【问题讨论】: