Jump to content

Downloading a file in php


pradeepa

Recommended Posts

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

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

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.