[英]File streaming in PHP - How to replicate this C#.net code in PHP?
I'm writing an interface to a web service where we need to upload configuration files. 我正在编写一个Web服务的接口,我们需要在其中上传配置文件。 The documentation only provides a sample in C#.net which I am not familiar with.
该文档仅在C#.net中提供了一个我不熟悉的示例。 I'm trying to implement this in PHP.
我正在尝试在PHP中实现这一点。
Can someone familiar with both languages point me in the right direction? 熟悉两种语言的人可以为我指明正确的方向吗? I can figure out all the basics, but I'm trying to figure out suitable PHP replacements for the FileStream, ReadBytes, and UploadDataFile functions.
我可以弄清楚所有基础知识,但是我正在尝试找出适用于PHP的FileStream,ReadBytes和UploadDataFile函数的替代品。 I believe that the RecService object contains the URL for the web service.
我相信RecService对象包含Web服务的URL。 Thanks for your help!
谢谢你的帮助!
private void UploadFiles() {
clientAlias = “<yourClientAlias>”;
string filePath = “<pathToYourDataFiles>”;
string[] fileList = {"Config.txt", "ProductDetails.txt", "BrandNames.txt", "CategoryNames.txt", "ProductsSoldOut.txt", "Sales.txt"};
RecommendClient RecService = new RecommendClient();
for (int i = 0; i < fileList.Length; i++) {
bool lastFile = (i == fileList.Length ‐ 1); //start generator after last file
try {
string fileName = filePath + fileList[i];
if (!File.Exists(fileName))
continue; // file not found
}
// set up a file stream and binary reader for the selected file and convert to byte array
FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fStream);
byte[] data = br.ReadBytes((int)numBytes); br.Close();
// pass byte array to the web service
string result = RecService.UploadDataFile(clientAlias, fileList[i], data, lastFile); fStream.Close(); fStream.Dispose();
} catch (Exception ex) {
// log an error message
}
}
}
For reading files, both on the local system and remotely over HTTP, you can use file_get_contents
. 要在本地系统上和通过HTTP远程读取文件,可以使用
file_get_contents
。
For POSTing to a web service, you should probably use cURL . 要发布到Web服务,您可能应该使用cURL 。 This article looks like a pretty good explanation of how to go about it.
本文看起来像一个很好的解释如何去做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.