how to access file from outside root directory in php

后端 未结 2 894
没有蜡笔的小新
没有蜡笔的小新 2020-12-20 08:15

I have a code to download zip files:

$dl_path = \'./\';  
$filename = \'favi.zip\';  
$file = $dl_path.$filename; 
if (file_exists($file))  {
  header(\'Cont         


        
2条回答
  •  囚心锁ツ
    2020-12-20 09:00

    First of all check if your script is running under the correct directory by echoing dirname(__FILE__).

    If it is running under public_html then you can change the code like this:

    $dl = dirname(__FILE__). '/../';
    

    But beware of security issue!

    1. Check if you have read/write permission on the file and directory
    2. Check the open_basedir restriction in php.ini (see How can I relax PHP's open_basedir restriction?)

    Hope this helps

提交回复
热议问题