Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write Post data to file with PHP

Tags:

text

http

post

php

I need to post data using the code below, to php file that will save it in a text file. I just don't know how to create the php file to receive the data below and save it in a text file. as simple as possible.

try {       // Add your data       List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);       nameValuePairs.add(new BasicNameValuePair("stringData", "12345"));       nameValuePairs.add(new BasicNameValuePair("stringData", "AndDev is Cool!"));       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));        // Execute HTTP Post Request       HttpResponse response = httpclient.execute(httppost);       String responseText = EntityUtils.toString(response.getEntity());      tv.setText(responseText);              } catch (ClientProtocolException e) {       // TODO Auto-generated catch block   } catch (IOException e) {       // TODO Auto-generated catch block   }   
like image 258
Mark Ismail Avatar asked Jan 20 '11 02:01

Mark Ismail


1 Answers

Simple as:

file_put_contents('test.txt', file_get_contents('php://input')); 
like image 197
Hamish Avatar answered Oct 04 '22 11:10

Hamish