Search code examples
phpandroidsudomkdir

Create directory on server from within the android app


How can I execute my php file which containsmkdir command from my android app? I tried giving root permission to my php file using visudo by following this link, but it still does not work.

However if I execute the php file from my terminal the directory gets created. So what do I need to do to make my android app execute this php file? Any idea ?

Below is my php file:

<?php
   $filename = $_POST['filename'];
   mkdir("./xyz/".$filename);
?>

And my Android Code for executing my php file (the core code):

 if(method == "POST"){
      DefaultHttpClient httpClient = new DefaultHttpClient();
      HttpPost httpPost = new HttpPost(url);
      httpPost.setEntity(new UrlEncodedFormEntity(params));

      HttpResponse httpResponse = httpClient.execute(httpPost);
      HttpEntity httpEntity = httpResponse.getEntity();
      is = httpEntity.getContent();
 }

Solution

    1. File Needs 777 permission
    2. Right Click on any folder and say permission in ftp [set 777]

      progratically in php:

      if (!file_exists('path/my_file')) {
          mkdir('path/my_file, 0777, true);
      }