简体   繁体   中英

Php content-disposition folder not working

I'm using header('Content-Disposition:...") to download files from a website. To set the path I use the next code:

$myPath = realpath('../wp-content/uploads/');

I know the path is OK by printing it in the console. So I use the following lines to download it:

$full_path=$myPath. '/myfile.csv';
header('Content-Disposition: attachment; filename=' . $full_path);
header("Pragma: no-cache");
header("Expires: 0");

Finally, it downloads the file, but the problem is the next one. Instead of downloading it in the right folder, it does it in the "downloads" folder of my computer, and the file name is the path of the folder but changing the '/' characters by '-'. For example: "-Applications-XAMPP-htdocs-myproject-wp-content-uploads-myfile.csv"

Any solution? Thank you so much

you cannot choose where you user will download the file. This is a browser settings that you cannot change. If you think about it if a website is allowed to save files where it wants it could be a very security thread because it can ovverride important system files.

I'm afraid that you cannot do much about it. Just put an alert or a message telling the user to save the file in the location that you want if the location is crucial for your project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM