You can find our user documentation at docs.cpanel.net.

Check out our new API beta site!

Child pages
  • UAPI Functions - Fileman::get_file_content
Skip to end of metadata
Go to start of metadata

Description

This function retrieves a file's content.

Important:

In cPanel & WHM version 76 and later, when you disable the File Storage role, the system disables this function.

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_&update_html_document_encoding=1



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


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


Note:

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


 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_ update_html_document_encoding=1


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. 
  • If you run CloudLinux™, you must use the full path of the uapi command:

    /usr/local/cpanel/bin/uapi


 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.

This parameter defaults to _DETECT_.

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

_DETECT_

 
to_charsetstring

The character set in which to encode the file.

This parameter defaults to _LOCALE_

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

_LOCALE_

 
update_html_document_encoding Boolean

Whether to update the file's HTML document encoding.

Note:

We added this parameter in cPanel & WHM version 86.

This parameter defaults to 1.

  • 1 — Update the file's HTML document encoding.
  • 0 — Don't update the file's HTML document encoding.
1 

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