Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 775
user1364259 Avatar asked Nov 13 '22 06:11

user1364259


1 Answers

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

like image 184
user1364259 Avatar answered Nov 16 '22 02:11

user1364259