Downloading .txt file problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pradeepa
Forum Newbie
Posts: 7
Joined: Sun Mar 01, 2009 11:33 pm

Downloading .txt file problem

Post by pradeepa »

Hi friends,

i used this code to download a file php

Code: Select all

<?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............ :banghead:
Thanks in advance
Dinosoles
Forum Newbie
Posts: 8
Joined: Fri Feb 20, 2009 1:07 am

Re: Downloading .txt file problem

Post by Dinosoles »

Hi,

Try...

Code: Select all

ob_clean();
flush();
just before the readfile.

Hope this helps.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Downloading .txt file problem

Post by requinix »

Yeah, doubt that will.

After the readfile() PHP will keep going, keep executing code. To make it stop use exit.
pradeepa
Forum Newbie
Posts: 7
Joined: Sun Mar 01, 2009 11:33 pm

Re: Downloading .txt file problem

Post by pradeepa »

i kept exit; after readfile() statement
it is working fine now.
Thanks a lot...........
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Re: Downloading .txt file problem

Post by shafiq2626 »

Helow every on i need a link which will download php fiel.
like sqlscript.php file.
pls help me
thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Downloading .txt file problem

Post by requinix »

shafiq2626 wrote:Helow every on i need a link which will download php fiel.
like sqlscript.php file.
pls help me
thanks
Look at the code in the first post. If that doesn't help you then create your own thread.
shafiq2626
Forum Commoner
Posts: 88
Joined: Wed Mar 04, 2009 1:54 am
Location: Lahore
Contact:

Re: Downloading .txt file problem

Post by shafiq2626 »

i have a php file and want to give facilit for clints to dwonload file.
i am using this scritp

$id =$_GET["id"];
if($id=="php")
{
header("Content-disposition: attachment; filename=aa.php");
readfile( $_SERVER['DOCUMENT_ROOT'] . "/ShoppinScript/aa.php");
}

echo "<a href='showscript.php?id=php'>Download the file to run script in your Div</a>";


/////////
to do this file download with success but the data on ctaining link file write in dwonloaded file.\
like i dwonload aa.php but the data of showscript.php also added in aa.php.
i need only aa.php data.
pls help me if possible.
pradeepa
Forum Newbie
Posts: 7
Joined: Sun Mar 01, 2009 11:33 pm

Re: Downloading .txt file problem

Post by pradeepa »

$id =$_GET["id"];
if($id=="php")
{
header("Content-disposition: attachment; filename=aa.php");
readfile( $_SERVER['DOCUMENT_ROOT'] . "/ShoppinScript/aa.php");
exit; //add this line it solves your problem
}
Post Reply