Page 1 of 1

Problem with PHP download

Posted: Tue Feb 09, 2010 3:57 pm
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

Re: Problem with PHP download

Posted: Tue Feb 09, 2010 6:36 pm
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.

Re: Problem with PHP download

Posted: Wed Feb 10, 2010 8:47 am
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