照片上传与参数到一个PHP页面 [英] Photo upload with parameters to a PHP page

查看:204
本文介绍了照片上传与参数到一个PHP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过PHP文件上传文件的服务器,我已经得到了这样的信息:

  

请打电话到:这些参数/uploadFiles.php:

     
      
  • $ _ POST ['USER_ID']
  •   
  • $ _ FILES ['形象']
  •   

所以,我的问题是什么是PHP调用带参数的$ _GET ['USER_ID']和$ _FILES [形象]的意思,而如何让我打电话到PHP成功地。

我已经为其他需要,成功地通过POST的方法,这样做调用服务器

  VAR的客户= Web客户端();
client.UploadStringCompleted + =新UploadStringCompletedEventHandler(client_UploadStringCompleted);
client.Headers [的Content-Type] =应用/的X WWW的形式urlen codeD;
client.Encoding = Encoding.UTF8;

字符串toSend =htt​​p://example.com/submit.php?userid=10;
client.UploadStringAsync(新的URI(toSend),POST,);
 

当然,我做了很多的研究,然后再发布,尝试了很多从这里议题的解决方案: <一href="http://stackoverflow.com/search?q=wp7+photo+upload">http://stackoverflow.com/search?q=wp7+photo+upload

感谢您在您的帮助。

更新:

我发现我需要的是模拟这种简单的HTML上传表单:

 &LT;形式方法=POST是enctype =的multipart / form-data的行动=HTTP:/myserver.com/upload.php'>
要上传的文件&LT;输入类型=文件名=图片&GT;&LT; BR&GT;
USER_ID&LT;输入类型=文字名称= USER_ID&GT;&LT; BR&GT;
&LT; BR&GT;
&LT;输入类型=提交值= preSS&GT;上传文件!
&LT; /形式GT;
 

当我运行这个在Web浏览器中我得到upload.php的反响不错,所以我只需要方法来模拟这种在WP7,我什么都试过,我很绝望。

我用 myToolkit 这个样子,但像当我用同样的反应Web客户端,restsharp,吊床:

  VAR请求=新HttpPostRequest(http://myserver.com/upload.php);
request.Data.Add(USER_ID,389096); // POST数据
request.Files.Add(新HttpPostFile(图像,,e.ChosenPhoto,真)); // POST文件
Http.Post(要求,RequestFinished);
 

解决方案

我想它了。我会发送不正确FilyType参数。 我发送图像/ JPG,为image / jpeg,图像/ PNG,但模拟HTML上传表单的时候,我们要送图像/ PJPEG。

我解释了吧,在细节,在这里(我用RestSharp): <一href="http://nediml.word$p$pss.com/2012/05/10/uploading-files-to-remote-server-with-multiple-parameters/#more-234" rel="nofollow">http://nediml.word$p$pss.com/2012/05/10/uploading-files-to-remote-server-with-multiple-parameters/#more-234

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: http://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);

解决方案

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

这篇关于照片上传与参数到一个PHP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆