pradeepa Posted January 21, 2009 Share Posted January 21, 2009 Hi friends, i used this code to download a file php <?php if(isset($_GET['uploadid'])) { // if id is set then get the file with the id from database $upid = $_GET['uploadid']; $recruid = $_GET['userid']; $resFile = $admin->getRecruiteruploadDetailsByUploadid($upid); $rowFile = mysql_fetch_array($resFile); $filename = $rowFile['File_Path']; $downloadFile = "../".$uploadsfolder."employeruploads/" . $recruid ."/".basename($filename); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header('Content-type: application'); header('Content-Disposition: attachment; filename=' . basename($filename) . ';'); $contentData = file_get_contents($downloadFile); readfile($downloadFile); } ?> it is working fine for all extensions like .doc,.pdf,.xls,.gif etc but when i download .txt file it is downloading the txt file with some extra code. The extra code is nothing but the php file where i wrote the above code. what is the problem? can anyone give me the solution please............ Thanks Link to comment https://forums.phpfreaks.com/topic/141721-downloading-a-file-in-php/ Share on other sites More sharing options...
RussellReal Posted January 21, 2009 Share Posted January 21, 2009 first of all this: $contentData = file_get_contents($downloadFile); does nothing in ur script second of all.. there is no extra data/whitespace beng shown.. it must be put into the DB when you UPLOAD it in there. - Russell Link to comment https://forums.phpfreaks.com/topic/141721-downloading-a-file-in-php/#findComment-741979 Share on other sites More sharing options...
pradeepa Posted January 21, 2009 Author Share Posted January 21, 2009 iam storing the uploaded file path in the database rather than total text Link to comment https://forums.phpfreaks.com/topic/141721-downloading-a-file-in-php/#findComment-742017 Share on other sites More sharing options...
Mark Baker Posted January 21, 2009 Share Posted January 21, 2009 is header('Content-type: application'); really setting a valid mime type? Link to comment https://forums.phpfreaks.com/topic/141721-downloading-a-file-in-php/#findComment-742094 Share on other sites More sharing options...
pradeepa Posted March 2, 2009 Author Share Posted March 2, 2009 yes it must be used to download any file extension types Link to comment https://forums.phpfreaks.com/topic/141721-downloading-a-file-in-php/#findComment-774399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.