i got a page index.php. i got a link over there to download.php.

in download.php i'll do some mysql things. (like count file download...) and redirect the browser to some file 123.zip.

Wot i really want is. I dont want to go to download.php instead the browser should remain in index.php while i store all data in db.
my link will be site.com/download.php?fileid=xx

and user should get the file in hand without goin to download.php. (i eman he should not go to some blank page (download.php))

i think i am clear.

please help

Dani AI

Generated

A simple, reliable way to keep the browser on index.php while recording the download server-side is to have the link target a hidden iframe (works with old and modern browsers). That keeps the main page visible, lets the server update the DB, and forces the browser download dialog without showing a blank row of PHP output. This builds on 's idea but avoids reloading the visible page and matches what wanted; 's surprise about the EXE shows the importance of correct headers.

HTML (client):

<iframe name="dlframe" style="display:none"></iframe>
<a href="download.php?fileid=123" target="dlframe">Download</a>

Server (download.php) responsibilities:

  • Validate and authorize the fileid (prevent path traversal).
  • Increment counters / log to DB.
  • Send strict download headers, then stream the file and exit. Example:
// validate $file
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($file));
header('Content-Disposition: attachment; filename="123.zip"');
readfile($file);
exit;

Modern alternative: use fetch() with responseType/blob and programmatically click a temporary <a download> to avoid navigation. Caveat: fetch buffers the whole file in memory, so it is unsuitable for very large files and breaks normal range/resume support.

Performance tip: for large/production files, log in PHP but hand the file serving to the webserver (X-Sendfile or X-Accel-Redirect) to avoid PHP memory/time limits and to preserve resume/range behavior. Always suppress any prior output, disable output compression for streams, and test across browsers.

Recommended Answers

All 4 Replies

You may use 'include' or 'require' to attach the download.php within your index file. The link to download file will be something like index.php?action=download&id=1234. When someone click the link, the index page will reload and by using isset($_GET), the page will call the download program and the user still in the index page.

I hope this help.

well thnks for the reply. but still i don want to reply. have a look at there try download links :) i want it to be like that! thnx

Hello bennetjosem
is it a joke??
when i click on download it's an exe file i get!!! :rolleyes: :sad:

well never mind that. just think hows that working??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.