How To Download File TO Desired FOLDER/Path?

I am having a problem with how to download the file into our desired folder, this below is my code for download.php

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($fileName));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header ("Cache-Control: must-revalidate");
header('Pragma: public');
ob_clean();
flush();
readfile($data);
echo $data;
exit;

I want to download the file to my desired folder like C:\Users\Asus or D:\Program not to the default one $data is the content of the file and $filename already include the extension Ex:picture.jpg

Thx before for all the help that i can get :)

Henry

Upvotes: 0

Views: 1249

Answers (2)

Quentin
Quentin

Reputation: 943097

There is no way to tell the client where on the client's disk to save a file to.

  • You have no way of knowing (on the WWW at least) what directories exist
  • If the user doesn't pay attention to where something is being saved (because they expect it to be the default) then you could save the file somewhere they wouldn't want it (such as a Startup folder) which would be a security risk.

Upvotes: 1

Dom
Dom

Reputation: 7315

The download directory is usually handled by the browser, not by the server or PHP it's self :)

Upvotes: 0

Related Questions