0

我创建了一个非常简单的 PHP 文件,它完成了非常简单的工作,它将图像从 Silverlight OutOfBrowser 应用程序流式传输到服务器,它在$_GET$_POST变量之间混合,事实上这是我非常简单的代码,我知道它缺乏安全,但我还是写了它只是为了确保我可以通过网络写入文件,并且它可以 100% 地上传多个文件等。

<?php
 //Gets 
  $myFile = $_GET['FileName'] ? $_GET['FileName'] : "input_stream.txt";
  $openedFile = fopen($myFile, 'w') or die("can't open file");  
  $input = file_get_contents("php://input");            
  fwrite($openedFile, $input);
  fclose($openedFile);

  //Check the mime type of the file (WRONG WAY)
  $mimeType = mime_content_type($myFile);   
  $input = null;    
  $finfo = finfo_open(FILEINFO_MIME_TYPE); 
  $mimeType = finfo_file($finfo, $myFile);
  echo $myFile . 'was uploaded, mime type : ' . $mimeType;
?>

那么是否有任何简单的 Ruby 替代方法来获取原始 POST 数据(这将是 Silverlight 的 ByteArray)?

4

2 回答 2

1

您可能希望使用 gem 进行 http 访问。这是一个:

https://github.com/jnunemaker/httparty

这个例子看起来像你需要的:

https://github.com/jnunemaker/httparty/blob/master/examples/basic.rb

于 2012-04-22T18:03:30.183 回答
0

如果你在 Rails 3 上,request.raw_post() 就是你要找的。见http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-raw_post

于 2012-05-09T17:18:22.407 回答