471,895 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,895 software developers and data experts.

Upload picture from winmobile (C#) using php

I know this is a commonly asked question, so sorry in advance, but even though it seems to be asked fairly frequently, I can't seem to find good code on it.

Essentially, I just want to upload a file to my website (on site-side using PHP & post) in windows mobile. Can anyone help me out? Sorry for the brevity, if you want details just let me know.
Nov 12 '08 #1
5 2883
5,000 Expert 4TB
What have you already tried?
Nov 13 '08 #2
648 Expert 512MB
Depending on your setup, a web service might be in order. If this is for Windows Mobile it is incredibly easy to add a web reference to a project that will accept something like a base64 string or byte[] to transfer your file, then your server side web service could read this in then create the file.
Nov 14 '08 #3
This is what I started, but I couldn't seem to get anything to happen...

EDIT: Bear in mind I've completely winged this. Truthfully I just don't have a clue and this was more of a guess/codejacking. My plan, Mark, actually was to send a byte array to a php script that acted as a web service. Unfortunately, I've never dealt with file transfers and as such, I don't even know how to do that! lol I'm at ground zero.

string localFile;
string uploadUrl;

Expand|Select|Wrap|Line Numbers
  1.             try
  2.             {
  4.                 FileStream rdr = new FileStream(localFile, FileMode.Open);
  5.                 byte[] inData = new byte[4096];
  6.                 int totbytes = 0;
  7.                 MemoryStream postData = new MemoryStream();
  8.                 int bytesRead = rdr.Read(inData, 0, inData.Length);
  9.                 while (bytesRead > 0)
  10.                 {
  11.                     postData.Write(inData, 0, bytesRead);
  12.                     bytesRead = rdr.Read(inData, 0, inData.Length);
  13.                     totbytes += bytesRead;
  14.                 }
  15.                 rdr.Close();
  16.                 postData.Position = 0;
  17.                 HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uploadUrl);
  18.                 req.Method = "POST";
  19.                 req.ContentLength = (long)postData.Length;
  20.                 using (Stream s = req.GetRequestStream())
  21.                 {
  22.                     s.Write(postData.ToArray(), 0, (int)postData.Length);
  23.                     postData.Close();
  24.                 }
  25.                 WebResponse resp = req.GetResponse();
  26.                 resp.Close();
  27.             }
  28.             catch (Exception ex)
  29.             {
  30.             }
  31.             finally
  32.             {
  33.             }
Nov 14 '08 #4
If anybody has any ideas, I would still appreciate it. I'm sadly still kind of stuck on this problem.
Dec 1 '08 #5
648 Expert 512MB

The easiest way to add a web service call to any .Net application is to make sre that the web service is externally exposed (i.e. available to connections) then use visual studio to add a web reference to your web service. Then all you have to do is create an instance of your web service then call your web method. It saves you manually invoking http requests etc.
Dec 3 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Oli | last post: by
1 post views Thread by alfredfx | last post: by
3 posts views Thread by samoore | last post: by
reply views Thread by simon2x1 | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.