I am doing a simple loading script where my users can upload their own images, etc.
But I have some strange problem.
When I uploaded the file, it had the contents from my index.php file no matter what type of file it uploaded. My code looks like this:
$fullPath = $r['snptFilepath'] . $r['snptFilename']; if (file_exists($fullPath)) {
$ r is the result from my database, where I saved the size, type, path, etc., when the file is uploaded.
UPDATE
When I upload and upload * .pdf files, it works with success. But when I try to download * .zip and text / rtf, the text / plain it acts strange.
By strange, I mean: it loads the full index.php file with the loaded contents of the file inside it.
ANSWER
I copied this from http://php.net/manual/en/function.readfile.php and now works. It seems that: ob_clean (); did the trick! Thanks for helping everyone.
#setting headers header('Content-Description: File Transfer'); header('Content-Type: '.$type); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit;
source share