PHP Hide Real Files Location From Clients And Display Contents.

Learn how you can hide your files real location with PHP from your clients and still be able to display contents of those files.

Last Update: Dec 03, 2021

PHP Hide Real Files Location From Clients And Display Contents.

Hello friend, today we are going to use PHP and hide the real location of your files from clients. Suppose that you are a web developer and you don't want client to access your files or know where you placed them, then we are going to show you how you can do that by just using PHP.

Note that for this tutorial, we are going to use an image as an example to show you how you can hide real files location, but you can use this method to hide your images, music, video, CSS files, JavaScript files. I have listed type of contents that you can hide the real path of, as I have practically done so in other projects.

We will be using base64 encoding to display and hide real path of files content, by using base64 clients will only see some junk of code without the real source location.

As we stated that we will use an image as an example we will display the image without hiding its location and display it with location been hidden. Well lets get to it.


    Author: Mr Parallel
    Tutorial: Hide Real File(s) Path
    function hidePath($source){
        /* Note that for the '$source' parameter, make sure to input the real location of a file.
           The location won't be visible to clients
        $content_type = mime_content_type($source); //Get what type of content is been passed
        $data = file_get_contents($source);
        $base64 = "data:$content_type;base64," . base64_encode($data);

        text-align: center;
        color: #007052;
        max-width: 350px;
        margin-bottom: 80px;

<!DOCTYPE html lang="en">
        <title>Hide real location of images and scripts using php</title>

        <h1>Image without hidden location</h1>
        <img src="screen0.png" alt="Image without location been hidden"/>
        <h1>Image with hidden location</h1>
        <img alt="Image with hidden location" src="<?php echo hidePath("screen0.png");?>"/>


From this code you will see that this will be the output:

As you can see, the image is still the same there's no difference, then lets inspect the images and see their resource location.

And now we can see that for the image with hidden location, the image "src" is just some chunk of unreadable code.

Well that's how you can hide your files real location, but bare in mind that this is not the only solution, there are other solutions outside this one.

Source Code: Download Source Code

Thank you for visiting the site.


Mr Parallel