public static function createFromLocalFile($file_name, $mime_type = null)
    {

        //Try to guess.  Might be questionable on non-*nix machines
        if ($mime_type === null) {
            $finfo = new \finfo(FILEINFO_MIME_TYPE);
            $info = $finfo->file($file_name);

            if ($info !== false) {
                $mime_type = $info;
            }
        }

        $content_length = filesize($file_name);
        $path_info = pathinfo($file_name);

        $instance = new self();
        $instance->fromStringArray([
            'MimeType' => $mime_type,
            'ContentLength' => $content_length,
            'FileName' => $path_info['basename'],
        ]);
        $instance->setLocalHandle(fopen($file_name, 'r'));

        return $instance;
    }
public static function createFromLocalFile($file_name, $mime_type = null)
    {

        //Try to guess.  Might be questionable on non-*nix machines
        if ($mime_type === null) {
            $finfo = new \finfo(FILEINFO_MIME_TYPE);
            $info = $finfo->file($file_name);

            if ($info !== false) {
                $mime_type = $info;
            }
        }

        $content_length = filesize($file_name);
        $path_info = pathinfo($file_name);

        $instance = new self();
        $instance->fromStringArray([
            'MimeType' => $mime_type,
            'ContentLength' => $content_length,
            'FileName' => $path_info['basename'],
        ]);
        $instance->setLocalHandle(fopen($file_name, 'r'));

        return $instance;
    }
public static function createFromLocalFile ( $ file_name , $ mime_type = null ) { //Try to guess.  Might be questionable on non-*nix machines if ( $ mime_type === null ) { $ finfo = new \ finfo ( FILEINFO_MIME_TYPE ) ; $ info = $ finfo -> file ( $ file_name ) ; if ( $ info !== false ) { $ mime_type = $ info ; } } $ content_length = filesize ( $ file_name ) ; $ path_info = pathinfo ( $ file_name ) ; $ instance = new self ( ) ; $ instance -> fromStringArray ( [ 'MimeType' => $ mime_type , 'ContentLength' => $ content_length , 'FileName' => $ path_info [ 'basename' ] , ] ) ; $ instance -> setLocalHandle ( fopen ( $ file_name , 'r' ) ) ; return $ instance ; }
Do this with a file handle please
Do this with a file handle please