Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

samalapsy's avatar

Creating Folder from a subdomain in Laravel into main domain in Laravel

I have 2 laravel files on my website, one is on a subdomain {sub.domain.com} and the other on the main domain {domain.com}.

I want to upload an image into the main public_html folder from the subdomain using Image intervention

The code below creates dynamic folder if it's not existing..

    $path = "uploads/listings/house/" . $slug;

    if(!File::exists("http://domain.com/".$path)){
            File::makeDirectory("http://domain.com/". $path, 0777, true);
            \Log::info('Driectory ' .$path. ' was created');
        }else{
            \Log::info('Driectory ' .$path. ' was NOT created');
        }

This code get the Image, add a watermark and save to the location created above

        $fileName = md5(time() .$image->getClientOriginalName()) ."." . strtolower($image->getClientOriginalExtension());
        $img = Image::make($image->getRealPath());
                
        // Main Photo
        $img->fit(1080, 620)->insert(public_path('img/logo.png'), 'center')->save($path . '/' . $fileName); 

The Issue

Trying to Upload, I receive a log message that the folder has been createdAfter having this, I get this error

Intervention\Image\Exception\NotReadableException: Image source not readable in /home2/username/laravel/vendor/intervention/image/src/Intervention/Image/AbstractDecoder.php:339

How can I achieve this

0 likes
5 replies
Snapey's avatar

You cannot use domain in a file path. It has to be a proper path within the file system. You need to think about the file structure of your server and build the path accordingly.

samalapsy's avatar

If I understand what you just said..It means it's not possibles....right....If yes

What about Uploading and Image from the subdomain to the main domain..is that still possible too..?

1 like
Snapey's avatar

it's possible if they are on the same physical server. Otherwise you would need to write an api to transfer files from one site to the other.

samalapsy's avatar

yes they are on the same physical servers

Snapey's avatar

you need to work out the correct path to the other site

Please or to participate in this conversation.