title: Android call php script to download file and save it in sd-card
body: <p>I am kind of new to php. I try to make an app in android that downloads a file from the eClass platform. I developed this script:</p>
  
  <pre><code>    &lt;?php
              $code=$_GET['code'];
              $code = stripslashes($code);
              $code = mysql_real_escape_string($code);
  
              $filename=$_GET['filename'];
              $filename = stripslashes($filename);
              $filename = mysql_real_escape_string($filename);
  
              $path = "C:\\xampp\\htdocs\\openeclass-2.5\\courses\\".$code."\\dropbox\\".$filename;
              $fullPath = $path.$_GET['download_file'];
  
              if ($fd = fopen ($fullPath, "r")) {
                  $fsize = filesize($fullPath);
                  $path_parts = pathinfo($fullPath);
                  $ext = strtolower($path_parts["extension"]);
                  switch ($ext) {
                      case "pdf":
                      header("Content-type: application/pdf"); // add here more headers for diff. extensions
                      header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // 
  
              use 'attachment' to force a download
                      break;
                      default;
                      header("Content-type: application/octet-stream");
                      header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
                  }
                  header("Content-length: $fsize");
                  header("Cache-control: private"); //use this to open files directly
                  while(!feof($fd)) {
                      $buffer = fread($fd, 2048);
                      echo $buffer;
                  }
              }
              fclose ($fd);
              exit;
              ?&gt;
  </code></pre>
  
  <p>which downloads the file when called from browser (in my localhost) and given code and filename as parameters in the url. Now I want to construct a function in my android app that calls this script, gets the file and saves it somewhere in the sd-card</p>
  
  <p>How can I achieve this?
  Also is it possible to be done in the emulator too? Thank you in advance!</p>