HEX
Server: nginx/1.28.3
System: Linux lightweb-s1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User: drdrivek-71 (1047)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /home/eslinced-103/brise-edu.or.kr/app/Services/UrlUploadedFile.php
<?php
namespace App\Services;

use Illuminate\Http\UploadedFile;
use App\Exceptions\CantOpenFileFromUrlException;

class UrlUploadedFile extends UploadedFile
{
    /**
     * @throws CantOpenFileFromUrlException
     */
    public static function createFromUrl(string $url, string $originalName = '', string $mimeType = null, int $error = null, bool $test = false): self
    {
        if (! $stream = @fopen($url, 'r')) {
            throw new CantOpenFileFromUrlException($url);
        }

        $tempFile = tempnam(sys_get_temp_dir(), 'url-file-');

        file_put_contents($tempFile, $stream);

        return new static($tempFile, $originalName, $mimeType, $error, $test);
    }


    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    public static function createFromPath($path): UploadedFile{

        $path_parts = pathinfo($path);

        $newPath = $path_parts['dirname'] . '/tmp-files/';
        if(!is_dir ($newPath)){
            mkdir($newPath, 0777);
        }

        $newUrl = $newPath . $path_parts['basename'];
        copy($path, $newUrl);
        $imgInfo = getimagesize($newUrl);

        return new UploadedFile(
            $newUrl,
            $path_parts['basename'],
            $imgInfo['mime'],
            filesize($path),
            true,
            TRUE
        );
    }
}