473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 2930
RedSon
5,000 Expert 4TB
What have you already tried?
Nov 13 '08 #2
markmcgookin
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.             {
  3.  
  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
markmcgookin
648 Expert 512MB
Cyprus,

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

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

Similar topics

2
by: NotGiven | last post by:
Please help me understand the big picture of allowing users to upload pictures and keep them separate and tied to their record in the database. I want the whole thing automated and I'm just...
2
by: Oli | last post by:
Hi Currently I have a simple form where users input and update their data. This works fine. However, we now have a need for users to be able to upload a picture to their profile. I have...
1
by: alfredfx | last post by:
i'm planning to develop a client server system the client and server both able to upload picture client will upload the picture to a folder that reside in the server while server user can also...
3
by: samoore | last post by:
Can you upload an image using a windows app. I either want to upload the image to a database or just a folder, but all of my searches show that you have to use a web app. I want to do this with a...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
7
by: dragiton | last post by:
SA Upload SQL Database variable types (image upload and storage) I am having trouble with the SA Upload utility. The following code used to work correctly. However, I lost my database and had to...
4
by: Cyprus106 | last post by:
I realize how I'm going about this is somewhat odd. I have to construct a program for windows mobile that only sends a couple queries to a remote MySQL server and hopefully gets some success/fail...
3
by: Cyprus106 | last post by:
I'm doing some geolocative work and do not, as of yet, have a map that I'm using in winmobile 6 SDK. I'd like to sync a map with some points up in the winmobile app. I'm wondering who knows where I...
0
by: simon2x1 | last post by:
i have an upload page called upload.php and a display upload called display.php while i make use of my wamp server on my localhost and i access upload.php to upload an image the image go to a folder...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.