Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel url download file

    public static function saveFile($file, int $id, string $file_path = 'user_photo', $type = 'url'): string
    {
        if (is_null($file)) {
            return '';
        }

        switch ($file_path) {
            case 'user_photo':
                $path = '/assets/images/'.$file_path;
                break;
            default:
                return '';
        }
        $extension = pathinfo($file, PATHINFO_EXTENSION);
        $file_path = $path.'/'.$id.'.'.$extension;
        if ($type === 'url') {
            if (!file_exists(public_path($path))) {
                if (!mkdir($concurrentDirectory = public_path($path), 0777, true) && !is_dir($concurrentDirectory)) {
                    throw new RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
                }
            }
            copy($file, public_path($file_path));

            return $file_path;
        }

        return false;
    }
Comment

PREVIOUS NEXT
Code Example
Php :: phpmyadmin centos 8 
Php :: Eloquent where date methods 
Php :: how to get woocommerce order details 
Php :: include() in php 
Php :: laravel collection has 
Php :: default language laravel 
Php :: date hour php 
Php :: laravel carbon time format 
Php :: check if checkbox is not checked laravel 8 
Php :: export to excel in php 
Php :: kartik select 2 yii2 
Php :: php clean user input 
Php :: How To Check If A String Ends With Another String In PHP 
Php :: php datetime from timestamp 
Php :: copy php array to another 
Php :: php PDO howto columns from table 
Php :: laravel signed Route custom domain 
Php :: php artisan tinker encryption cmd 
Php :: gettype() function in PHP 
Php :: how to get all the records with same ID in laravel 
Php :: laravel get data in pivot table 
Php :: filter var php function 
Php :: php one hour in the future 
Php :: php add custom button in wordpress editor 
Php :: php date list 
Php :: htaccess redirect https laravel 
Php :: php get current page url 
Php :: symfony messenger rabbitMQ 
Php :: laravel check if api request 
Php :: php slice array in half 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =