日期:2014-05-17 浏览次数:20539 次
<?php
$data = $GLOBALS[HTTP_RAW_POST_DATA];
if(empty($data)) {
$data = file_get_contents('php://input');
}
if($data){
$file = fopen(time().'.wav','w');//打开文件准备写入
$data = gzuncompress($data);
fwrite($file,$data);//写入
fclose($file);//关闭
echo "ok~~~";
}else echo 'Failed';
var ms = new MemoryStream();
Request.InputStream.CopyTo(ms);
var data = ms.ToArray();
if (data.Length > 0)
{
var time = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
FileStream fs = new FileStream(time + ".wav", FileMode.Create);
var gzip = new GZipStream(new MemoryStream(data), CompressionMode.Decompress);
gzip.CopyTo(fs);
gzip.Close();
fs.Close();
Response.Write("ok~~~");
}
else
Response.Write("failed");
// 假设只有一个文件上传
HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];
// #4是复制到一个新的内存流,这里直接使用原始流
Stream compressedStream = postedFile.InputStream;
using (MemoryStream decompressStream = new MemoryStream()) {
using (GZipStream gzip = new GZipStream(compressedStream, CompressionMode.Decompress, true)) {
byte[] buffer = new byte[1024];
int offset = 0;
while ((offset = gzip.Read(buffer, 0, buffer.Length)) > 0) {
decompressStream.Write(buffer, 0, offset);
}
buffer = null;
}
decompressStream.Position = 0;