Note that there are some explanatory texts on larger screens.

plurals
  1. POBinary mode writing
    primarykey
    data
    text
    <p>I am writing a php program to write a binary file (may be video or image files). I would like to make it as a web service and call it from another application like c#, mac etc.</p> <p>My code is give below,</p> <pre><code>&lt;?php $fileChunk = $_POST["filechunk"]; $vodFolder = 'D:\\HYSA SVN\\Trunk\\workproducts\\source\\hysa_he\\web\\entertainment\\'; $vodFile = $vodFolder . "abcd.mov"; $fh = fopen($vodFile, 'ab'); flock ($fh, LOCK_EX); $varsize = fwrite($fh, $fileChunk); fclose($fh); ?&gt; </code></pre> <p>But when I called the php web service from a c# code, the abcd.mov is creating in the location, but its size is only one kb. I suspects that, the writing in halted when a character ‘&amp;’ found in the binary file. I read the php documentation and found that, fopen with binary mode ‘b’ will solve this issue? But it is not working. Can somebody help me ?</p> <p>This is my c# code.</p> <pre><code>BinaryReader b = new BinaryReader(File.Open("d:\\image38kb.jpg", FileMode.Open)); int pos = 0; int length = (int)b.BaseStream.Length; byte[] bt = b.ReadBytes(length); char[] ch = b.ReadChars(length); HttpWebRequest request = null; Uri uri = new Uri("http://d0327/streamtest.php"); request = (HttpWebRequest)WebRequest.Create(uri); NetworkCredential obj = new NetworkCredential("shihab.kb", "India456*", "tvm"); request.Proxy.Credentials = obj; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = bt.Length; using (Stream writeStream = request.GetRequestStream()) { UTF8Encoding encoding = new UTF8Encoding(); byte[] bytes = encoding.GetBytes("filechunk="); byte[] rv = new byte[bytes.Length + bt.Length]; System.Buffer.BlockCopy(bytes, 0, rv, 0, bytes.Length); System.Buffer.BlockCopy(bt, 0, rv, bytes.Length, bt.Length); writeStream.Write(rv, 0, bt.Length); } string result = string.Empty; using ( HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8)) { result = readStream.ReadToEnd(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload