473,765 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect if file download completed or cancelled

I have a large install file (an exe) on my web server that people
download and install from. Looking at my log files, I see a lot of
people downloading it, but no way to tell for sure if they completed the
download or cancelled out before it completed. Is there any function in
PHP that would allow the web server to send the file and detect a
completion or cancellation? Or perpahs a javascript/PHP method?

Any help would be greatly appreciated.
Thanks,
Dan
Oct 18 '06 #1
2 23900
You could check the byte count in the web server log to see if the
whole file was transferred.

In PHP, you could also do this by checking connection_abor ted() after
sending the file. For example:

ignore_user_abo rt(true); // Don't end if the connection breaks

if (readfile($path ) !== false && !connection_abo rted()) {
// Success!
}

Here's a larger example. The function sendFile returns the status of
the download:

<?

// Sample usage

function sendTest()
{
$res = sendFile('appli cation.exe', 'application/octet-stream');

if ($res['status']) {
// Download succeeded
} else {
// Download failed
}

@saveDownloadSt atus($res);
}

// The sendFile function streams the file and checks if the
// connection was aborted.

function sendFile($path, $contentType = 'application/octet-stream')
{
ignore_user_abo rt(true);

header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' .
basename($path) . "\";");
header("Content-Type: $contentType");

$res = array(
'status' =false,
'errors' =array(),
'readfileStatus ' =null,
'aborted' =false
);

$res['readfileStatus '] = readfile($path) ;
if ($res['readfileStatus '] === false) {
$res['errors'][] = 'readfile failed.';
$res['status'] = false;
}

if (connection_abo rted()) {
$res['errors'][] = 'Connection aborted.';
$res['aborted'] = true;
$res['status'] = false;
}

return $res;
}

// Save the status of the download to some place

function saveDownloadSta tus($res)
{
$ok = false;
$fh = fopen('download-status-' . $_SERVER['REMOTE_ADDR'] . '-' .
date('Ymd_His') , 'w');
if ($fh) {
$ok = true;
if (!fwrite($fh, var_export($res , true))) {
$ok = false;
}
if (!fclose($fh)) {
$ok = false;
}
}
return $ok;
}

Dan D wrote:
I have a large install file (an exe) on my web server that people
download and install from. Looking at my log files, I see a lot of
people downloading it, but no way to tell for sure if they completed the
download or cancelled out before it completed. Is there any function in
PHP that would allow the web server to send the file and detect a
completion or cancellation? Or perpahs a javascript/PHP method?

Any help would be greatly appreciated.
Thanks,
Dan
Oct 20 '06 #2
Thank you very much. That looks like it should work great. I'll give it
a try.
Dan

pe*******@gmail .com wrote:
You could check the byte count in the web server log to see if the
whole file was transferred.

In PHP, you could also do this by checking connection_abor ted() after
sending the file. For example:

ignore_user_abo rt(true); // Don't end if the connection breaks

if (readfile($path ) !== false && !connection_abo rted()) {
// Success!
}

Here's a larger example. The function sendFile returns the status of
the download:

<?

// Sample usage

function sendTest()
{
$res = sendFile('appli cation.exe', 'application/octet-stream');

if ($res['status']) {
// Download succeeded
} else {
// Download failed
}

@saveDownloadSt atus($res);
}

// The sendFile function streams the file and checks if the
// connection was aborted.

function sendFile($path, $contentType = 'application/octet-stream')
{
ignore_user_abo rt(true);

header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' .
basename($path) . "\";");
header("Content-Type: $contentType");

$res = array(
'status' =false,
'errors' =array(),
'readfileStatus ' =null,
'aborted' =false
);

$res['readfileStatus '] = readfile($path) ;
if ($res['readfileStatus '] === false) {
$res['errors'][] = 'readfile failed.';
$res['status'] = false;
}

if (connection_abo rted()) {
$res['errors'][] = 'Connection aborted.';
$res['aborted'] = true;
$res['status'] = false;
}

return $res;
}

// Save the status of the download to some place

function saveDownloadSta tus($res)
{
$ok = false;
$fh = fopen('download-status-' . $_SERVER['REMOTE_ADDR'] . '-' .
date('Ymd_His') , 'w');
if ($fh) {
$ok = true;
if (!fwrite($fh, var_export($res , true))) {
$ok = false;
}
if (!fclose($fh)) {
$ok = false;
}
}
return $ok;
}

Dan D wrote:
>>I have a large install file (an exe) on my web server that people
download and install from. Looking at my log files, I see a lot of
people downloading it, but no way to tell for sure if they completed the
download or cancelled out before it completed. Is there any function in
PHP that would allow the web server to send the file and detect a
completion or cancellation? Or perpahs a javascript/PHP method?

Any help would be greatly appreciated.
Thanks,
Dan

Oct 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3038
by: IGC | last post by:
I have a requirement to record in a database when a file is finished downloading to the end-user. Currently when a user clicks a download icon for a file it directs to an ASP page that records the "hit" into a database, then I use a response.redirect "filename.exe" to point the user to the download. What I'm missing is knowing when the download is complete so I can update the database to show the file successfully completed its download....
1
1307
by: alocin | last post by:
in my aspx page's page_load i got: Dim imageData() As Byte=allegato Response.ClearContent() Response.ClearHeaders() Response.AppendHeader("Content-Length", imageData.Length.ToString) Response.ContentType = "application/octet-stream" Response.AddHeader("content-disposition", "attachment; filename=goofy") Response.BinaryWrite(imageData)
5
3034
by: RC | last post by:
how to detect file is completely downloaded from client by following code? <%@ Page language="C#" debug="true" %> <script language="C#" runat="server"> private void Page_Load(object sender, System.EventArgs e) { Response.ContentType="application/zip"; Response.AppendHeader("Content-Disposition","attachment; filename=myzipfile.zip"); Response.WriteFile(@"c:\inetpub\wwwroot\myzipfile.zip"); Response.Flush();
5
4893
by: Dan D | last post by:
I have a large install file (an exe) on my web Apache server that people download and install from. Looking at my log files, I see a lot of people downloading it, but no way to tell for sure if they completed the download or cancelled out before it completed. Are there any known methods that would allow the web server to send the file and detect a completion or cancellation? Or perhaps a javascript method or html request trick that would...
3
2142
by: tshad | last post by:
I have a function that downloads a file to the users computer and it works fine. The problem is that I then want the program to rename the file (file.move) to the same name plus todays date. The problem is that when you run the program it gets to the: Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name)
1
1786
by: test | last post by:
I'm trying to develop a small inhouse file download tool I need to detect all files downloaded from internetexplorer and display a custom interface i.e. when ever the user tries to download a file from IE, then a custom .net interface needs to be displayed or AT LEAST both i need to somehow intercept the file download event in IE
2
2626
by: Mark Anderson | last post by:
Is it possible to identify the action of a user cancelling by the user of file download dialog? (as opposed to something else being captured. Ideally I'd like to do this for a IE6+/FF v1.5+/Safari v1.2+ base. [I've a pass through ASP page capturing calls to a download component that doesn't logs activity and which I can't edit. As my ASP page logs the calls before download, a cancel by the user means the d/l count is 1 too high. As this...
1
8454
by: Tim B | last post by:
Is there a way in javascript to detect that the file download dialog box has appeared or has closed? Suppose I have a form that when submitted makes a request that could take awhile to complete. The response would be a file generated on the server - e.g. a pdf file. When the form is submitted I show some sort of message or graphic, like "please wait...". When the file is ready and a dialog box pops up indicating it's ready, or when the user...
1
47483
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.