Problem with PHP download

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gcreddy
Forum Newbie
Posts: 10
Joined: Tue Sep 08, 2009 8:26 am

Problem with PHP download

Post by gcreddy »

Hello,

I developed a client login system and I have run into a little trouble when downloading files from the server. I am calculating the variable called $file and using the following code:

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header("Content-Disposition: attachment; filename=\"" . basename($file) . "\"");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: private');
header('Pragma: private');
ob_clean();
//flush();
readfile($file);
}

Once in a while, when someone tries to download this file, the entire folder (in which the file exists) or all the other files (including the current file) get deleted for no reason. Can someone tell me why this is happening?

Regards,
G.C.Reddy
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Problem with PHP download

Post by JakeJ »

well, you should always have uploaded files go to a temp directory (and virus checked) then moved to be with your other files, but I have no idea why it would be deleting anything. Make sure your your permanent directory only allows some other user to delete files. Not really a solution if your code is causing a problem, but you should do it anyway.
gcreddy
Forum Newbie
Posts: 10
Joined: Tue Sep 08, 2009 8:26 am

Re: Problem with PHP download

Post by gcreddy »

Hi Jake,

Thank you for the help. I have found the problem. Some other part of my code was being executed unintentionally. I could fix it.

Thanks again!

Regards,
G.C.Reddy
Post Reply