Jump to content

Set a variable when download start


habeebnet

Recommended Posts

Here's my file download script....
[code]
set_time_limit(0);
$speed = 10;

header("Cache-control: private");
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Length: ' . filesize($fileLocation . $fileName));
header('Content-Disposition: attachment; filename=' . $fileName);

if (!$file = fopen($fileLocation . $fileName, 'r')) {
      exit();
}

while (!feof($file)) {
      echo fread($file, $speed * 1024 * 8);
      flush();
      sleep(1);
}[/code]

when this script runs, a file dialogue box will appear with a 'save' and 'cancel' button.. I'm looking for a way to set a variable (say $status=TRUE) TRUE when somebody clicks on save button. And  when downlaods completes, the variable should set to FALSE.

I trying to implement this for the last two days... but always the variable will set to to TRUE before i click 'Save'..

Can anybody help me?

Many Thanks
-Hab-
Link to comment
Share on other sites

Hmm now that i think about it... It probably is impossible... Since a webserver has no way of knowing if your web client is downloading anything... Hmm but wait... maybe it does know since its a constant connection...  Seems like it would almost take a packet sniffer lol... As far as I know its not a php function or anything... But I'm sure its possible...
Link to comment
Share on other sites

while you can't possibly set a variabe within the same script from javascript, you can, however, use AJAX or set a cookie with javascript. but i haven't seen any javacript code to listen to file download dialogs, and if you output the javascript in this same script, it will be treated as the text content of the file... maybe use frames.

as far as i know, jsp might be able to sniff packets :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.