Dit is een truucje om via een Javascript met het aanroepen van een PHP script toch bestanden te downloaden van externe bronnen!, daarom is dit script ook bedoelt om op/via een webserver te draaien.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
<html> <head> <script src="jquery.js"></script> <title>Java CORS voorbeeld</title> </head> <body> <script> $(document).ready(function(){ var fileurl = 'http://www.website.nl'; var filename = 'bestand.ext'; //Voer het bestand 'download.php' uit en wacht totdat het klaar is met downloaden (jQuery/Ajax). $.ajax({ async: false, type: 'GET', url: 'download.php?url=' + fileurl + '&filename='+ filename, success: function(data) {} }); }); </script> </body> </html> |
|
<?php file_put_contents($_GET['filename'], file_get_contents($_GET['url'])); ?> |
Voorbeeld gebruik:
http://mijnwebsite.nl/download.php?url=http://website.nl/bestand.xml&filename=bestand.xml