File Download (with file_put_contents)


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. // Define Filename and Download link
  4. $file_name = 'mediawiki-1.17.0.tar.gz';
  5. $download_link = 'http://download.wikimedia.org/mediawiki/1.17/mediawiki-1.17.0.tar.gz';
  6.  
  7. // Download File Content
  8. $file_data = file_get_contents($download_link);
  9.  
  10. // Create File
  11. $handle = fopen($file_name, 'w');
  12. fclose($handle);
  13.  
  14. // Save Content to file
  15. $downloaded = file_put_contents($file_name, $file_data);
  16. if($downloaded > 0)
  17. {
  18. echo 'Datei wurde erfolgreich heruntergeladen!<br>';
  19. }
  20.  
  21. exec('tar xfvz '. $file_name, $extract);
  22.  
  23. if($extract > 0)
  24. {
  25. echo 'Datei wurde entpackt';
  26. }
  27.  
  28. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.