Page 1 of 1

Downloading .txt file problem

Posted: Sun Mar 01, 2009 11:42 pm
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

Re: Downloading .txt file problem

Posted: Tue Mar 03, 2009 11:52 pm
by Dinosoles
Hi,

Try...

Code: Select all

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

Hope this helps.

Re: Downloading .txt file problem

Posted: Wed Mar 04, 2009 12:05 am
by requinix
Yeah, doubt that will.

After the readfile() PHP will keep going, keep executing code. To make it stop use exit.

Re: Downloading .txt file problem

Posted: Wed Mar 04, 2009 12:07 am
by pradeepa
i kept exit; after readfile() statement
it is working fine now.
Thanks a lot...........

Re: Downloading .txt file problem

Posted: Wed Mar 04, 2009 2:01 am
by shafiq2626
Helow every on i need a link which will download php fiel.
like sqlscript.php file.
pls help me
thanks

Re: Downloading .txt file problem

Posted: Wed Mar 04, 2009 2:39 am
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.

Re: Downloading .txt file problem

Posted: Wed Mar 04, 2009 4:35 am
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.

Re: Downloading .txt file problem

Posted: Wed Mar 04, 2009 4:46 am
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
}