-1

I want only my download.php file (on my wwebsite) to be able to download my Java.zip file So, I created the .htaccess file and inside there is:

<files Java.zip>
  Order allow,deny
  Deny from all
</files>

SO, when I go the the url http://my-website.com/Java.zip there is good an acces denied, that is good

but now, I want my PHP file to be able to download automatically Java.zip (in about 3 secondes after loading the page), so, how to do it ?

I made researches with google but I found nothing... I need help.

  • [readfile()](http://www.php.net/manual/en/function.readfile.php) with appropriate headers – Mark Baker Apr 09 '16 at 21:32
  • No, not readfile, because when I go to download.php via my url, it download the file and no load the page download.php. Me, I want to load my page download.php, then, read readfile('Java.zip') with headers – Mathieu Nightown Apr 09 '16 at 21:38
  • You can't download a file and display a new html page at the same time; http only allows one response too one request – Mark Baker Apr 09 '16 at 21:41
  • @MathieuNightown, consider using ajax request in 3 seconds after page load – RomanPerekhrest Apr 09 '16 at 21:43
  • So, how can I do to... 1. I pay with index.html a starpass...... 2. If the paiement is okay, I go to download.php (the starpass script is okay)....... 3. Only after loading download.php I want to download my file.... AND I don't want the visitor to download the file writing download.php directly from URL.... – Mathieu Nightown Apr 09 '16 at 21:43
  • What i the puropose of this AJAX request ? AJAX will force the download ? – Mathieu Nightown Apr 09 '16 at 21:45
  • I want my download.php file to download Java.zip ONLY after download.php is succesfully loaded... Because in the top of my download.php file, I have a starpass script that allows the load of download.php ONLY if the paiement was good. SO, How to do it ? – Mathieu Nightown Apr 09 '16 at 21:46
  • I think you should add the `download.php` file contents to your question. Also, add tag `javascript` – RomanPerekhrest Apr 09 '16 at 22:23
  • You could `include` the download if the starpass script is successful. This also looks promising http://stackoverflow.com/questions/7127153/php-how-can-i-block-direct-url-access-to-a-file-but-still-allow-it-to-be-downl?rq=1 – Steve Apr 10 '16 at 04:29

1 Answers1

0

if you want to force a download from a php file, you should specify this action in the header using header function and the readfile function

header('Content-disposition: attachment; filename=Java.zip');
header('Content-type: application/zip');
readfile($PATH_TO_YOUR_FILE);
exit;

Regards.

Idir Ouhab Meskine
  • 587
  • 1
  • 9
  • 23
  • I want my download.php file to download Java.zip ONLY after download.php is succesfully loaded... Because in the top of my download.php file, I have a starpass script that allows the load of download.php ONLY if the paiement was good. – Mathieu Nightown Apr 09 '16 at 21:41
  • You can use js to do a redirection once you starpass scripts check the payment or try to reload the site with a parameter to "active" the headers. Regards! – Idir Ouhab Meskine Apr 09 '16 at 21:50
  • A js to do a redirection to Java.zip ? Yes, but will it work ? Because I blocked Java.zip from .htaccess deny from all... – Mathieu Nightown Apr 09 '16 at 21:51
  • It doesn't work with a js redirection because I blocked Java.zip from .htaccess deny from all.. . for information I want only the js redirection to be able to download Java.zip from download.php. But I don't want that the visitor download directly from typing Java.zip in the url.... – Mathieu Nightown Apr 09 '16 at 21:54
  • Do us understand that I send a software with starpass ? – Mathieu Nightown Apr 09 '16 at 22:01
  • Yes, I understand your question and also your problem but you are trying to do something very difficult because you want to do a single request but in the same request you want to wait and check the js and then download a file through the same php file. You can do only one thing, don't check the script and do only one request or wait to the javascript and then send a second request to your server. – Idir Ouhab Meskine Apr 09 '16 at 22:09