A
A
AlexPal4inskiy2014-07-02 22:41:51
PHP
AlexPal4inskiy, 2014-07-02 22:41:51

How to implement the display of your files for each user of the site from the same directory?

It is necessary that an authorized user sees his files at http://domain.com/files/myfile.pdf, but the file is actually stored in a folder, for example, /allfiles/user1/myfile.pdf. At the same time, everyone needs that when displaying images in this way, they load quickly, just like from a real directory, and get into the browser cache.
I tried this:
header('Content-type: image/png');
readfile($_SERVER['DOCUMENT_ROOT'].'/allfiles/user1/image.png');
But such an implementation significantly slows down the output of images.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2014-07-02
@BuriK666

use nginx and X-Accel-Redirect

R
Rsa97, 2014-07-03
@Rsa97

Return a 301 redirect and the actual url of the file.

<?php
  header(“HTTP/1.1 301 Moved Permanently”);
  header(“Location: {$_SERVER['DOCUMENT_ROOT']}/allfiles/user1/image.png”);
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question