Page tree
Skip to end of metadata
Go to start of metadata

 

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?dir=home%2Fusername%2Fpublic_html&file=example.html&charset=utf-8&from_charset=_DETECT_&to_charset=_LOCALE_

 

Note:

This example calls the UAPI function via a cPanel session. For more information, read our Guide to UAPI documentation. 

 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_',
	)
);

Note:

For more information, read our Guide to the LiveAPI System.

 

 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_',
		}
 );

Note:

For more information, read our Guide to the LiveAPI System.

 

 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 %]

Note:

For more information, read our Guide to Template Toolkit documentation. 

 

 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.
  • For more information and additional output options, read our Guide to UAPI documentation or run the uapi --help command. 
  • We introduced this functionality in cPanel & WHM version 56.

 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 (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.

   

Parameters

ParametersTypeDescriptionPossible valuesExample
dirstring

Required

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

The absolute path to the directory./home/user/public.html
filestring

Required

The files to retrieve.

A valid filename. example.html
from_charsetstring

The system's predefined encoding.

  • An encoding language.
  • _DETECT_auto-detect the selected file’s encoding type.

_DETECT_

 
to_charsetstring

The character set in which to encode the file.

  • An encoding language.
  • _LOCALE_look up the current locale's encoding language.

_LOCALE_

 

Returns

ReturnTypeDescriptionPossible valuesExample
dirstring

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

A valid absolute path./home/user/public_html
filenamestringThe file's name.A valid filename.example.html
pathstringThe path to the file.A valid absolute path./home/user/public_html/example.html
contentstringThe file's contents, encoded in the UTF-8 character set.A string value."hi"
from_charstring

The file's character set.

A cPanel-supported character set encoding.

 

UTF-8
to_charstring

The file's new character set.

A cPanel-supported character set encoding.

 

UTF-8