How to download a file from php page using phonegap (Android platform)? -


i'm using phonegap create android application ,in app i'd allow user download file php page (server side) ,that's i'm having troubles . here html page index.html android project :

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8" />     <title>download</title> </head>  <body>      <form id="down" name="down" action="http://172.25.10.99/test/download.php" method="get">     <!-- 172.25.10.99 : server ip -->         <input type="text" name="filename" id="filename"/>         <input type="submit" id="id2" value="download"/>      </form> </body> </html> 

and here php page download.php :

        <?php      try {         $file = "d:\\file\\" . $_request['filename'];     } catch (exception $ex) {         $file = "d:\\file\\pdf2.pdf";     }     $fp = fopen($file, 'r');     $content = fread($fp, filesize($file));     fclose($fp);     header("accept-ranges: bytes");     header("keep-alive: timeout=15, max=100");     header("content-disposition: attachment; filename=" . basename($file));     header("content-type: application/octet-stream");     header("content-transfer-encoding: binary");     header("content-description: file transfer");  ?> 

the problem : i'm getting nothing when press download button in application (after inserting file name correct , exists on server), while i'm expecting see download window asks me save requested file ,or better ,to find requested file in download folder downloaded automatically ,and believe problem somewhere in header in php page.could please ? i'd appreciate ..

use filetransfer.download, here example:

function downloadfile(){  window.requestfilesystem(localfilesystem.persistent, 0,      function onfilesystemsuccess(filesystem) {         filesystem.root.getfile(         "dummy.html", {create: true, exclusive: false},          function gotfileentry(fileentry) {             var spath = fileentry.fullpath.replace("dummy.html","");             var filetransfer = new filetransfer();             fileentry.remove();              filetransfer.download(                 "http://www.w3.org/2011/web-apps-ws/papers/nitobi.pdf",                 spath + "thefile.pdf",                 function(thefile) {                     console.log("download complete: " + thefile.touri());                     showlink(thefile.touri());                 },                 function(error) {                     console.log("download error source " + error.source);                     console.log("download error target " + error.target);                     console.log("upload error code: " + error.code);                 }             );         }, fail);     }, fail); }; 

}


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -