带参数的照片上传到PHP页面 [英] Photo upload with parameters to a PHP page
问题描述
我需要通过 .php 文件将文件上传到服务器,我得到了以下信息:
I need to upload file the server via .php file, and i've got this information:
使用以下参数调用:/uploadFiles.php:
Make a call to the: /uploadFiles.php with these parameters:
- $_POST['user_id']
- $_FILES['图片']
所以,我的问题是使用参数 $_GET['user_id'] 和 $_FILES['image'] 调用 php"是什么意思,以及如何成功调用 php.
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.
出于其他需要,我已经通过POST"方法成功调用了服务器,如下所示:
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", "");
当然,我在发帖之前做了很多研究,从这里的主题中尝试了很多解决方案:https://stackoverflow.com/search?q=wp7+photo+upload
Of course, I did much research before posting, tried a lot of solutions from topics here: https://stackoverflow.com/search?q=wp7+photo+upload
预先感谢您的帮助.
更新:
我发现我需要的只是模拟这个简单的 HTML 上传表单:
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>
当我在网络浏览器中运行它时,upload.php 得到了很好的响应,所以我只需要在 WP7 中模拟它的方法,我尝试了一切,我很绝望.
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.
我像这样使用了 myToolkit,但与使用 webclient 时的响应相同,restsharp,吊床:
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);
推荐答案
我想通了.我发送了错误的 FlyType 参数.我正在发送图像/jpg、图像/jpeg、图像/png,但是在模拟 HTML 上传表单时,我们必须发送图像/pjpeg".
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".
我在这里详细解释了它(我使用了 RestSharp):http://nediml.wordpress.com/2012/05/10/uploading-files-to-remote-server-with-multiple-parameters/#more-234
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
这篇关于带参数的照片上传到PHP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!