Question How to store ZIP via PHP

mrsharp

New member
Joined
Jul 23, 2017
Messages
2
Programming Experience
1-3
Hallo, first I want to say sorry for my bad englisch (I have only school englisch).
I'm new here in this network.

I have a problem. The C# application must create a zip, after that, the application will send a request to the php file, which will store the file on the server. There is a structure on the file, because there is a login system. When the user will login, he will have the oppertunity to download the zip locally. But this code does not work, wheres the error?

C# upload code:
C#:
 DirectoryInfo d = new DirectoryInfo(hauptpfad);                ZIP = Path.ChangeExtension(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), d.Name), ".zip");


                ZipFile.CreateFromDirectory(hauptpfad, ZIP, CompressionLevel.Optimal, false);


                var client = new RestClient("https://domain.com/test/");
                var request = new RestRequest("server.php", Method.POST);
                  request.AddParameter("ac", "xs");
                 request.AddFile("uploads", ZIP);
                request.AddParameter("id", networkid);
                IRestResponse response = client.Execute(request);


                MessageBox.Show(response.Content);

php code (for returning the file):
PHP:
 $targetPath = '............/' .$_POST["id"]. '/Devassist/' . $_POST["filename"];		echo $targetPath;				header("Cache-Control: public");		header("Content-Description: File Transfer");		header("Content-Disposition: attachment; filename=$targetPath");		header("Content-Type: application/zip");		header("Content-Transfer-Encoding: binary");
		readFile($targetPath);		exit();

and the c# code for storing the returned file locally:
C#:
 var client = new RestClient("https://domain.com/test/");                var request = new RestRequest("server.php", Method.POST);
                request.AddParameter("ac", "jdl");
                request.AddParameter("id", user_id.ToString());
                request.AddParameter("filename", Path.ChangeExtension(Daten, ".zip"));
                byte[] response = client.DownloadData(request);


                // Speichert empfangene Serverdaten
                File.WriteAllBytes(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Server.zip"), response);
                ZipFile.ExtractToDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Server.zip"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Testorder Server"));

But this does not work. Wheres the error?
 
What does "does not work" actually mean? If there's an error then there's an error message. That is important diagnostic information and it's important that you pass that on to us.
 
Theres no specific error message. The length of the zip of my pc and of the server are different (I mean the bytes). And when the application extract the zip, there is the message that the zip hasn't got a valide format
 
Back
Top Bottom