Can I access the ThinkPHP picture file without saving it in the Public directory?

there is a requirement that users must log in to the system to see the pictures. If they do not log in, they will not be able to see them. Put the picture in the public directory, it"s external, anyone can see it if you don"t log in, but if you don"t put it in the public directory, the browser can"t access the picture file, is there any way to solve it?

Mar.15,2022

if you want to set access permissions, it is convenient to use PHP , and use PHP to write an interface for downloading files. Here is demo

.
class Index extends Controller
{
    public function file()
    {
        $filename = $_GET['filename'];

        // 
        // dosomething

        // 
        $s = new sendfile();
        $file = '/data/file/' . $filename;
        try {
            $s->send($file);
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
    }
}
http-send-file

you can configure your protected image directory in nginx or apache to jump to the specified file of your project by default, which will determine the permissions and then decide whether to display the image.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e320bb-266c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e320bb-266c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?