php - Serve static files from another server while keeping the process invisible


What I am trying to achieve is to serve files from an S3 bucket for multiple websites without showing the real path of the items. The files are stored in the S3 bucket like: bucket/website



I do not want to create S3 buckets for every website, so I want to store all the files in a bucket folder and serve them from there with a script.

I currently got:


    $path = "domain";
    $file = "filename";

    // Save a copy of the file
    file_put_contents($file, fopen($path . $file, 'r'));

    // Set the content type and output the contents
    header('Content-Type: ' . mime_content_type($file));

    // Delete the file


but it's not that clean since I save the file and then output it. Saving the file could potentially cause a mess due to the fact that the websites might have files with the same name. I'm also lacking the .htaccess file to make the proper rewrites so it would appear that you got the file from and not a

Any suggestions on how to realize this would be great! Many thanks in advance!

People are also looking for solutions to the problem: PHP if statement and ob_flush


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.