OK, firstly, I'm sorry, because I understand that this is a topic that has been considered many times before - believe me, I know, I read all the previous questions and answers and still can not get it to work.
I have a folder containing downloadable files. For security reasons, I found this file outside of webroot. However, despite all my efforts, I can not get my php script to download the file.
I am using Apache Linux VPS server using Plesk 11.
The structure (simplified) of the file is as follows. The folder httpdocsis the web root. The folder private/uploadedfileswhere I want to download.
-var
- www
- vhosts
- mydomain.org.uk
- httpdocs (webroot)
- private
- uploadedfiles
I am using jQuery ajax call to pass a file name to a PHP script called downloadscript.php. This script is inside the web root httpdocs. The script looks like this:
<?php
$filename = $_POST['fbpath'];
$path = '/var/www/vhosts/mydomain.org.uk/private/uploadedfiles/' . $filename;
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($path));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($path));
ob_clean();
flush();
readfile($path);
exit;
?>
Ajax call works without problems, but I get the following error message in my PHP logs:
PHP Warning: readfile(/var/www/vhosts/mydomain.org.uk/private/uploadedfiles/filename.docx): failed to open stream: No such file or directory
I checked, double checked and checked the triple, and the file definitely exists inside the folder uploadedfiles.
I also verified that this is not a limitation problem open_basedir- I am sure that it is not.
I'm sure there is something really simple that I am missing - where am I going wrong?
As an add-on, I haven't written a script to upload files yet - is there anything I need to know in advance before continuing this?
Thank!