views:

85

answers:

3

Here is what I am trying to do: I am making a custom text file containing a test. This test is unique to the user and well I don't want my server to stack all those text files.

Is there a way to use Ajax/JavaScript/jQuery to find if the user has already finished the download and if they have get a return value (1 if finished) so the response can be sent back to the PHP file and it can delete that file off the server (real-time like)?

I know there are plenty of ways to do this using PHP. Sort of like run clean up upon user log out and so on but I wanted to try using the method above since it can have many other applications that might be cool to use. I tried most search engines but they have nothing close to what I need.

Any Thoughts or ideas are welcome.

+1  A: 

Why do you need to store them in a file? Just use a PHP script or such that creates the test and outputs it directly to the user. That's how it will get deleted when the download is complete.

Tatu Ulmanen
This is the best way to do it. What you want to use is the Content-Disposition header. There's an example on the PHP docs for the header function: http://php.net/manual/en/function.header.php
Jordan Reiter
A: 

If it's important you may want the user to return to your server with the hash of the downloaded file. If the hash matches you know two things:
1. The user downloaded the file successfully
2. It's now ok to delete the file

MyGGaN
Gotta disagree with this. Few people are familiar with hashing files. I'm not even sure if everyone would have this software installed.
Jordan Reiter
I might have misunderstood the question. If the user needs to download a file to disc my solution is not good. But if the "test" just needs to be downloaded (like viewed in a browser) you could have the hash function in JavaScript and no need for any installed programs. (The problem above only state that the test is stored in a text file on server, not how it's supposed to be viewd by client).
MyGGaN
A: 

Well it is very simple. I don't know how to make a PHP webpage send itself to the user other than to make the PHP make a text file and force send that to the user. This creates the problem of having so many text files in a temporary folder.

Now if the test required say 15 chapters each having a text or HTML format file then the script neatly zips all those files and sends them to the user. Again falling on the same problem if the user is finished downloading I am trying to get any type of script to delete the temporary zip or text file out of the temporary directory in somewhat real time.

If I could MD5 a downloaded file using JavaScript I welcome it and it would be a hack solution to the problem but how will the JavaScript gain access to the root access of the download folder of the user? There are security issues there if I am not mistaken. Hope this helps round the question a bit more.

Stax