Jump to content

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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.