Description

This function retrieves a file's content.

Examples




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_

 



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

 



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

 



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

 



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



{  
   "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"
  }
}



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