Php content folder unavailable

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

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

      

I know the path is ok by typing 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 as follows. Instead of downloading it to the correct folder, it does so in the downloads folder on my computer, and the filename is the path to the folder, but changing the "/" to "-". For example: "-Applications-XAMPP-htdocs-myproject-wp-content-uploads-myfile.csv"

Any solution? Thank you very much.

+3


source to share


1 answer


you cannot choose where the user will upload the file. These are browser settings that you cannot change. If you think about it, if a website is allowed to save files wherever it wants, it can be a very secure thread as it can overwrite important system files.



I’m afraid there’s not much you can do. Just provide a warning or message telling the user to save the file in the location you want if location is critical to your project.

+1


source







All Articles