Files re-appearing after removal

Ok…this question will have most of you saying “Why the heck would you do it like that, that is retarded.”…but here it goes.

All the data on my website(videos, images, audio…) is stored in a mysql database. As of right now all images stream directly from the database and the videos open as follows:

Due to the fact that I have yet to find an efficient way of streaming from a database it currently dumps the data to a temporary file then displays the video and then deletes it.(in order to protect my content I believe this to be at least 1 extra step in that the video can only be viewed via my website and if someone were to try to download it they most likely would not be able to as it only resides there long enough for the player to grab the file.The part im having trouble with is the deleting part… The script does as follows:

opens database
dumps data into a file
outputs the site displaying the movie
executes a script(using this line:
exec(“php deleteTempVideo.php filename=$tempName > /dev/null &”);
) dumping the output to something is required so that the main script can continue on. otherwise the user would have to wait 5 seconds and then the video would already have been deleted.

The script at the end does the following:

sleeps for 5 seconds
unlinks the file(I also tried executing an rm command, same result)
(it is my understanding from other projects in php that when using the unlink command it does not interfere with current downloads but prevents further downloads and permanently removes the file once the current downloads complete. Please correct me if im wrong)

So im wondering where my goof may have been…what sort of anomoly can cause the file to be deleted and then be recovered or recreated soon thereafter? (the site is currently not available to anyone but me, so its not just a coincidence)

If you have a better suggestion on how to protect my videos feel free to mention it here. All movies added are converted to flv format and displayed in a flash player, so keep that in mind when offering advice. An ultimate solution to my problem would be if I could use a php script to supply the flv file, but all attempts at that have failed…if I could do that I could have the main script insert a unique key into a db table and then the download script can find and remove that key, if it found it it would send the movie, otherwise the person is trying to download it from some other page, or theyre trying to use the src in the html code to grab it.

I’m almost speechless. Your usage of the database may cause huge scaling problems and drastically impact the db performance for others.

A more traditional way to handle this is to store your files in a private disk folder and create a unique link in a public directory for the download. After creating the link, I’d expect the same kind of thing you’re doing so it might not solve your problem but it would eliminate the storage in the DB (DB’s are not really suited to holding large BLOBs) and the extra file copy from the DB before actually serving the file.

Maybe someone else can address the unlink issue.