473,698 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

check if file was downloaded

Hi,

I use the following code to offer a download:

header("Content-Type:$mimetype" );
header("Content-Disposition: attachment; filename=$filen ame");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
header("Content-Length:".filesi ze($temp_filena me));
readfile_chunke d($temp_filenam e);

(readfile_chunk ed comes from
http://nl2.php.net/manual/nl/function.readfile.php)

My question: how can I check if the file was downloaded and saved? I want to
make an automatic removal possible after download.

The function seems to exit when the user clicks cancel and doesn't download
the file, so all following commands will not get executed. That's perfect.

However, it doesn't when the file is small enough to fit in a chunk. php's
readfile seems to have the same behaviour. So, in that case, all following
commands do get executed, even if cancel was clicked (and in my application,
the file then gets removed, which shouldn't happen of course).

Also checking the bytes sent doesn't help. If the function exists, it always
returns the complete filesize for the small files that fit in a single
chunk, even if cancel was clicked.

So, is there any working way to determine if a file was downloaded and
opened/saved instead of cancel being clicked in the download dialog?

Thanks in advance, best regards,
-Hendri Adriaens.
Feb 23 '07
11 10342
Well, not really, somewhat slower, but mainly somewhat headvier on the
server.
Ok, thanks. So, a chunksize of 1 byte should be optimal for my purpose. I
will
test the load differences for the server.
Nope, it's in the browser itself, the cancelling of a download isn't a
HTTP feature. You can add a dialogue on the page, or possibly something
with javascript, it will not help: the browser dialogue will still come
into play in the end.
Bad luck.
There may be a possibility to load the file into a hidden frame or
something, and to check that with javascript. This will not help your php
script, but javascript could fire a request on succes, ans you only delete
the file on that second request. It would mean nothing get's deleted with
javascript disabled, and I'm a little bit fuzzy on the details...
Ok, no problem, me neither.
Then again: I do not know what the exact purpose of you script is in
general, maybe it's OK to keep the small files and delete them
periodically after a check with filemtime()?
I just wanted to offer users of a sharing environment to remove the file
from
the server automatically after the file was downloaded. So a period clean up
is not really what I want. I don't want to remove files that shouldn't be
removed.

But thanks for your help and answers! But if you find any other ideas than
chunksize=1, I will be more than happy to test them :)

Best regards,
-Hendri.
Feb 23 '07 #11
Ok, thanks. So, a chunksize of 1 byte should be optimal for my purpose. I
will
test the load differences for the server.
Strangely enough, this doesn't work either...

I have 3 files:
a 19.4 MB
b 159 KB
c 1.03KB

With the previous chunksize (1*1024*1024 bytes), the script continued even
when cancel was clicked for files b and c, but not for a. With a chunksize
of 1 byte, it doens't continue for a and b, but still does for c. So the
script would still conclude that it was downloaded even if cancel was
clicked.

If anyone has an idea how this works and how I could get a script to
correctly report whether a file was actually downloaded or not, please let
me know.

Thanks, best regards,
-Hendri.
Feb 23 '07 #12

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

Similar topics

2
5480
by: tgundeck | last post by:
Does anyone know how I can check the file size of photos or any file type in JavaScript? I'm allowing users to store photos in my web page using the input type = file tag, but need to limit the photo size to 1 meg. I would like to check the file size in JavaScript on the page, instead of on the server. Anyone know how I can check the file size in JavaScript?
2
5358
by: David | last post by:
I'm using following code for checking a file existence. I's working fine for given folder. Is there a way to check a file exitance in subfolders? Thanks in advance, David Option Compare Database Public Function adhFileExists(strName As String) As Boolean On Error Resume Next
7
33467
by: andylcx | last post by:
Hi all: The c++ language can check whether the file exist or not. I am wondering how c language does this job? Thanks a lot! Andy
4
2600
by: lawrence | last post by:
Using <INPUT type"file" runat="server"> to upload a file. When the file size is too large I get a "page cannot be display" error. Thats cool I'm down with that. But is there a way to check for file size (client or server side), so that error doesn't occur? Thanks --Dietrich
3
3682
by: Loane Sharp | last post by:
Hi there I use the FileStream object to download a zip file over the internet to my local disk. The file downloads successfully, but when I attempt to unzip it, I'm told that the file is in use by another process. This occurs even if I release the object using fs.Close() and fs = Nothing. Please help (my code is given below) Best regards
3
30201
by: puja | last post by:
hi all, In asp.net 2.0 there is a limit on file size upload of 4MB. I know this limit can be increased in web.config file. Is there any way to check the file size before upload ? if user is trying to upload file size more than 4MB then just display a message that file size is too big and can't be uploaded. thanks
1
4273
by: jtertin | last post by:
I am currently using the following code to make sure a file is writable (i.e. is not in use) by using the CanWrite method of the FileStream object. Using the code below, the TextWriter is still trying to write to the file and is throwing an exception (File... in use by another process) whenever the output file (strFileName) is open. I am trying to prevent it from writing to it at all if this is the case... Any insight? Public...
2
1176
by: shadow2284 | last post by:
i'm trying to download full tilt poker and i've downloaded it before but i reformatted my computer and now when i go to download it it says i'm downloading "download.php" when it's finished downloading i get the message windows cannot open file. Then i have two choices, use web service to find appropiate program or select program from a list. I've tried downloading different stuff of php sites but have no idea which one i need. I'm so...
2
9830
Manikgisl
by: Manikgisl | last post by:
HI. How to check File exists in Web Share C# try { WebRequest request = HttpWebRequest.Create("http://www.microsoft.com/NonExistantFile.aspx"); request.Method = "HEAD"; // Just get the document headers, not the data. request.Credentials = System.Net.CredentialCache.DefaultCredentials; // This may throw a WebException:
3
8265
Frinavale
by: Frinavale | last post by:
Hi there! I'm hoping that someone knows how to check the size of a file before it is uploaded to the server using JavaScript. I have seen suggested solutions using an ActiveX control to check the file size; however, I'm not happy with this solution because my application is designed to work in multiple browsers and ActiveX is limited to Internet Explorer. I cannot check the file size on the web server because IIS throws the following...
0
8604
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
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
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
8895
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
8861
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...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
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
2001
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.