Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php curl将zip文件上载到远程服务器_Php_Curl_Upload_Zip_Sfx - Fatal编程技术网

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

使用php curl将zip文件上载到远程服务器,php,curl,upload,zip,sfx,Php,Curl,Upload,Zip,Sfx,现正进行下列工作: 1) 客户端使用API调用从服务器请求ZIP文件。 2) 他提供了一个回调url,该url是API请求中的aspx程序。 3) 我们使用php CURL脚本创建ZIP文件,将ZIP文件上载到他的aspx程序 问题是,当文件上传到他的服务器上时,ZIP文件格式会发生变化(变为SFX ZIP存档)。如果使用简单的php脚本将同一文件上载到我们的服务器,则格式保持不变。我们不确定问题是在于我们使用CURL上传文件的方式,还是在于客户端在其服务器上保存ZIP文件的方式 CURL代码如

现正进行下列工作: 1) 客户端使用API调用从服务器请求ZIP文件。 2) 他提供了一个回调url,该url是API请求中的aspx程序。 3) 我们使用php CURL脚本创建ZIP文件,将ZIP文件上载到他的aspx程序

问题是,当文件上传到他的服务器上时,ZIP文件格式会发生变化(变为SFX ZIP存档)。如果使用简单的php脚本将同一文件上载到我们的服务器,则格式保持不变。我们不确定问题是在于我们使用CURL上传文件的方式,还是在于客户端在其服务器上保存ZIP文件的方式

CURL代码如下所示:

$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);
客户端提供了用于保存数据的aspx代码:

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();
        }

    }

提前谢谢。

您保存了
SavePost
不保存任何内容吗? 如果您试图从this.Page.Request.InputStream读取,请参阅如何转换它

顺便说一句,另见。这表明您还可以使用(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)));
}