Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
655 views
in Technique[技术] by (71.8m points)

c# - Photo upload with parameters to a PHP page

I need to upload file the server via .php file, and i've got this information:

Make a call to the: /uploadFiles.php with these parameters:

  • $_POST['user_id']
  • $_FILES['image']

So, my question is what does "call php with parameters $_GET['user_id'] and $_FILES['image']" mean, and how do I make a call to php sucessfully.

I've already, for other needs, succesfully made call to the server via "POST" method, like this:

var client = WebClient();
client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompleted);
client.Headers["Content-Type"] = "application/x-www-form-urlencoded";
client.Encoding = Encoding.UTF8;

string toSend = "http://example.com/submit.php?userid=10";
client.UploadStringAsync(new Uri(toSend), "POST", "");

Of course, I did much research before posting, tried a lot of solutions from topics here: https://stackoverflow.com/search?q=wp7+photo+upload

Thank you in advance for your help.

Update:

I found out all i need is to simulate this SIMPLE HTML UPLOAD form:

<form method='POST' enctype='multipart/form-data' action='http:/myserver.com/upload.php'>
File to upload <input type=file name=image><br>
user_id <input type=text name=user_id><br>
<br>
<input type=submit value=Press> to upload the file!
</form>

When i run this in web browser i get good response from upload.php, so i just need the way to simulate this in WP7, i tried everything, i'm desperate.

I used myToolkit like this, but same response like when i used webclient, restsharp, hammock:

var request = new HttpPostRequest("http://myserver.com/upload.php");
request.Data.Add("user_id", "389096"); // POST data
request.Files.Add(new HttpPostFile("image", "", e.ChosenPhoto, true)); // POST file
Http.Post(request, RequestFinished);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I figured it out. I was sending incorrect FilyType parameter. I was sending image/jpg, image/jpeg, image/png, but when simulating HTML upload form we have to send "image/pjpeg".

I explained it, in details, here (i used RestSharp): http://nediml.wordpress.com/2012/05/10/uploading-files-to-remote-server-with-multiple-parameters/#more-234


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...