skip to Main Content

How To Upload file from https://subdomain.laravel.com/ to https://assets.laravel.com/

Example your project on https://subdomain.laravel.com/

'assets' => [
    'driver' => 'local',
    'root' => public_path('assets/images'), // Path ke folder 'images' dalam folder 'assets'
    'url' => 'https://assets.laravel.com/', // URL publik untuk mengakses file
    'visibility' => 'public',

2

Answers


  1. Generally, if you want to serve uploaded assets from another domain, you can use cloud storage.
    Check out the AWS S3+CloudFront architecture.
    The official Laravel Vapor also uses this architecture.

    The idea of ​​"uploading to another domain" is wrong.

    Login or Signup to reply.
  2. if you want to save your file to another subdomain its possible with two ways:

    1: if your subdomain are in same server then you can locate with file directory path

    2: If both server or different then you can make service for that to uploaf file by FTP or SFTP method its best way

    Configure the FTP Disk in config/filesystems.php

    'ftp' => [
        'driver'   => 'ftp',
        'host'     => env('FTP_HOST'),
        'username' => env('FTP_USERNAME'),
        'password' => env('FTP_PASSWORD'),
    
        // Optional FTP Settings...
        'port'     => env('FTP_PORT', 21),
        'root'     => env('FTP_ROOT', ''),
        'passive'  => true,
        'ssl'      => false,
        'timeout'  => 30,
    ],
    

    Set Up Environment Variables

    FTP_HOST=ftp.example.com
    FTP_USERNAME=your_username
    FTP_PASSWORD=your_password
    FTP_PORT=21
    FTP_ROOT=/path/to/root
    

    strong textUpload File via FTP

    
    use IlluminateSupportFacadesStorage;
    
    $filePath = storage_path('app/public/yourfile.txt'); 
    $ftpPath = 'remote-directory/yourfile.txt';
    
    // Upload the file
    Storage::disk('ftp')->put($ftpPath, fopen($filePath, 'r+'));
    
    

    Handling Errors

    use IlluminateSupportFacadesStorage;
    use IlluminateSupportFacadesLog;
    
    $filePath = storage_path('app/public/yourfile.txt');
    $ftpPath = 'remote-directory/yourfile.txt';
    
    try {
        if (Storage::disk('ftp')->put($ftpPath, fopen($filePath, 'r+'))) {
            Log::info('File uploaded successfully.');
        } else {
            Log::error('Failed to upload the file.');
        }
    } catch (Exception $e) {
        Log::error('FTP upload failed: ' . $e->getMessage());
    }
    

    This code help to uploads a file from your Laravel application to a remote server using FTP.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search