UAPI Functions - Fileman::get_file_content

Description

This function retrieves a file's content.

Examples


 cPanel or Webmail Session URL

https://hostname.example.com:2083/cpsess##########/execute/Fileman/get_file_content%3Fdir%3D%2Fhome%2Fusername%2Fpublic_html%26file%3Dexample.html%26charset%3Dutf-8%26from_charset%3D_DETECT_%26to_charset%3D_LOCALE_

 LiveAPI PHP Class

$cpanel new CPANEL(); // Connect to cPanel - only do this once.
  
// Retrieve content from file.
$get_file_content $cpanel->uapi(
    'Fileman''get_file_content',
        array(
        'dir'           => '/home/user/public_html',
        'file'          => 'example.html',
        'from_charset'  => '_DETECT_',
        'to_charset'    => '_LOCALE_',
    )
);

 LiveAPI Perl Module

my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
  
# Retrieve Content from file.
my $get_file_content $cpliveapi->uapi(
 'Fileman''get_file_content',
        {
        'dir'           => '/home/user/public_html',
        'file'          'example.html',
        'from_charset'  => '_DETECT_',
        'to_charset'    => '_LOCALE_',
        }
 );

 cPanel Template Toolkit

<!-- Get a hash of all the data, then display the content value. -->
[% data = execute( 'Fileman', 'upload_files' {dir => '/home/user/public_html, 'file' => 'example.html', 'from_charset' => '_DETECT_', 'to_charset' => '_LOCALE_'} ); %]
[% FOREACH q = data.content %]
     <p>
         [% q %]
     </p>
[% END %]
  
<!-- Get only a hash of the data. -->
[% execute('Fileman', 'upload_files' {dir => '/home/user/public_html, 'file' => 'example.html', 'from_charset' => '_DETECT_', 'to_charset' => '_LOCALE_',}  ).data.content %]

 Command Line

uapi --user=username Fileman get_file_content dir=%2Fhome%2Fusername%2Fpublic_html file=example.html charset=utf-8 from_charset=_DETECT_ to_charset=_LOCALE_

 

Notes:

  • You must URI-encode values.
  • username represents your account-level username.

 Output (JSON)

   "messages":null,
   "errors":null,
   "status":1,
   "metadata":{ 
 
  },
  "data": {
    "from_charset": "utf-8",   
    "filename": "example.html",
    "to_charset": "utf-8",
    "content": ""hi"",
    "path": "/home/username/public_html/example.html",
    "dir": "/home/username/public_html"
  }
}

 

Note:

Use cPanel's API Shell interface (Home >> Advanced >> API Shell) to directly test cPanel API calls.

 

Parameters

 Parameters 

 Type 

Description

Possible values

Example

dir

string

Required

 The file path to the directory that contains the selected file. 

The absolute path to the directory.

 /home/user/public.html 

file

string

Required

The files to retrieve.

A valid filename.

 example.html

from_charset

string

The system's predefined encoding.

  • An encoding language.
  • _DETECT_ — auto-detect the selected file’s encoding type.

_DETECT_

 

to_charset

string

The character set in which to encode the file.

  • An encoding language.
  • _LOCALE_ — look up the current locale's encoding language.

_LOCALE_

 

 

Returns

Return

Type

Description

Possible values

Example

dir

 string 

 The file path to the directory that contains the selected file. 

A valid absolute path.

/home/user/public_html

filename

string

The file's name.

A valid filename.

example.html

path

string

The path to the file.

A valid absolute path.

 /home/user/public_html/example.html 

content

string

The file's contents, encoded in theUTF-8 character set.

A string value.

"hi"

 from_char 

 string

The file's character set.

A cPanel-supported character set encoding.

 

UTF-8

to_char

 string

The file's new character set.

 A cPanel-supported character set encoding. 

 

UTF-8

 

  • 8 Users Found This Useful
Was this answer helpful?

Related Articles

The cPanel Interface

For  cPanel  &  WHM  version  58 Overview The cPanel interface is...

User Preferences

For cPanel & WHM version 58 Overview This document outlines how to access your cPanel...

Manage External Authentications

For cPanel & WHM version 58 Overview Manage credentials Additional documentation...

What is cPanelID?

In This Article:  Overview ServicesHow to get a cPanelID cPanelID External...

Guide to cPanel Interface Customization - cPanel Style Development

Introduction You can develop custom styles that modify the appearance of the cPanel interface....