dro59505 2013-04-24 07:57
浏览 192

使用php curl将zip文件上传到远程服务器

Following is being done: 1) Client requests a ZIP file from our server using an API call. 2) He provides a call back url which is an aspx program in the API request. 3) We create the ZIP file, using php CURL script upload the ZIP file to his aspx program.

The issue is, the ZIP file format changes (to SFX Zip archive) when the file gets uploaded on his server. If the same file is uploaded to our server using a simple php script the format remains unchanged. We are not sure if the issue is with the way we are uploading the file using CURL or if its with the way the client is saving the ZIP file on his server.

The CURL code is as following :

$download_file = "/tmp/test.zip";
$callBackUrl = "http://www.remoteurl/theclients_uploadcode.aspx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => "@$download_file"));
curl_setopt($ch, CURLOPT_URL, $callBackUrl);
curl_exec($ch);
curl_close($ch);

The client provided the aspx code for saving the data:

private void SavePost()
{
   HttpPostedData = ReadFully(this.Page.Request.InputStream);
   Timestamp = DateTime.Now.ToString("MMddyyyy-hhmmss");
   Timestamp = Timestamp.Replace("-", "").Replace(" ", "").Replace(":", "");                      
   if (FileName.ToString() == string.Empty)
   {
    FileName = Timestamp;
   }
   if (FileName.Contains(".zip") == false)
   {
    FileName = FileName + ".zip";
   }
   tempFilePath = (tempFilePath + FileName);
   Response.Write((tempFilePath + ("  HttpPostedData:" + HttpPostedData)));
}

 public static byte[] ReadFully(Stream input)
    {

        byte[] buffer = new byte[16 * 1024];
        using (MemoryStream ms = new MemoryStream())
        {
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                ms.Write(buffer, 0, read);
            }
            return ms.ToArray();
        }

    }

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douzi9430 2013-04-24 12:56
    关注

    you save SavePost don't save anything? you try to read from this.Page.Request.InputStream, see FileUpload to FileStream how to convert it.

    btw see also How to read inputstream from HTML file type in C# ASP.NET without using ASP.NET server side control. This shows you can also use (c#):

    HttpPostedFile file = Request.Files["file"];
    if (file != null && file.ContentLength )
    {
        string fname = Path.GetFileName(file.FileName);
        file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示