Log in

View Full Version : Change default download location



round
06-25-2012, 07:40 AM
Hello,

I am struck with one problem, In my below code i am trying to download csv file from other server and wanted to save it on my root directory but it is going to save on My local Downloads folder. Is there anyway to change my download location?
I wanted to download it on my server not in my Downloads folder.
can any one help me?


<?php
$ok = true;
//echo "out";

//echo $_SERVER['REQUEST_URI'];
$name = substr($_SERVER['REQUEST_URI'],0,strrpos($_SERVER['REQUEST_URI'],'/'));

if( $ok )
{
$file_path = "http://www.bseindia.com/bhavcopy/eq200612_csv.zip";
$path_parts = pathinfo($file_path);
$file_name = $path_parts['basename'];
$file = @fopen($file_path,"rb");
//echo "In";
if ($file)
{
header("Cache-Control: public");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=\"{$file_name}\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($file_path));

while(!feof($file))
{
echo fread($file, 500*1024);
//echo readfile($file);
flush();
if (connection_status()!=0)
{
@fclose($file);
die();
}
}
@fclose($file);

exit;
}
else
echo "Invalid File Request";
}

?>

Thanks in Advance.

bernie1227
06-25-2012, 10:45 AM
Hiya round,
Please encase your code in [CODE] tags :)
I think this (http://http://stackoverflow.com/questions/3938534/download-file-to-server-from-url) could help you.
Bernie

round
06-25-2012, 10:56 AM
Bernie thanks for your reply,

I didnt get what you want to say.
Can you please explain?

Thank you.