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:
php code (for returning the file):
and the c# code for storing the returned file locally:
But this does not work. Wheres the error?
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?