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

 

Description

This function saves a file in a directory and encodes it in a character set.

Examples


 cPanel or Webmail Session URL
https://hostname.example.com:2083/cpsess##########/execute/Fileman/save_file_content?&dir=/home/username/public_html&file=example.html&from_charset=utf-8&to_charset=utf-8&content="hi"&fallback=0

 

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.
 
// Save example.html's content.
$save_file_content = $cpanel->uapi(
    'Fileman', 'save_file_content',
		array(
		'dir'			=> 'public_html',
		'file'			=> 'example.html',
		'from_charset'		=> 'UTF-8',
		'to_charset'		=> 'ASCII',
		'content'		=> '"hi"',
		'fallback'		=> '0',
 )
);

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.
 
# Save example.html's content.
my $ save_file_content = $cpliveapi->uapi(
 	'Fileman', 'save_file_content',
		{
		'dir'			=> 'public_html',
		'file'			=> 'example.html',
 		'from_charset'		=> 'UTF-8',
		'to_charset'		=> 'ASCII',
		'content'		=> '"hi"',
		'fallback'		=> '0',
		}
 );

Note:

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

 cPanel Template Toolkit
<!-- Get a hash of all the data, then display the path value. -->
[% data = execute( 'Fileman', 'upload_files' {dir => 'public_html, 'file' => 'example.html', 'from_charset' => 'UTF-8', 'to_charset' => 'ASCII', 'content' => '"hi",} ); %]
[% FOREACH q = data.path %]
     <p>
         [% q %]
     </p>
[% END %]
 
<!-- Get only a hash of the data. -->
[% execute('Fileman', 'upload_files' {dir => 'public_html, 'file' => 'example.html', 'from_charset' => 'UTF-8', 'to_charset' => 'ASCII', 'content' => '"hi",}  ).data.path %]

Note:

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

 Command Line
uapi --user=username Fileman save_file_content dir=/home/username/public_html file=example.html from_charset=utf-8 to_charset=utf-8 content="hi" fallback=0

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",
    "to_charset": "utf-8",
    "path": "/home/username/public_html/example.html"
  }
}


Note:

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

Parameters

ParametersTypeDescriptionPossible valuesExample
dirstring

The directory that contains the selected file.

This parameter defaults to the user's /home directory.

A valid directory name.public_html
filestring

Required

The files to retrieve.

A valid filename.example.html
from_charsetstring

The character set encoding of the content parameter's value.

This parameter defaults to UTF-8.

Any cPanel-supported character encoding.

UTF-8

to_charsetstring

The character set encoding in which to encode the file.

This parameter defaults to UTF-8.

Any cPanel-supported character encoding.

ASCII

contentstring

The new file's contents.

If you do not use this parameter, the function creates a blank file.

A string value.hi
fallbackBoolean

Whether the function will return an error or save in the default character set if it cannot save in the specified character set.

This parameter defaults to 1.

  • 0 — Return an error.
  • 1 — Save in the default character set.
0

Returns

ReturnTypeDescriptionPossible valuesExample
pathstringThe path to the file.A valid absolute file path./home/user/public_html/example.html
from_charsetstring

The file's character set.

Any cPanel-supported character set encoding.UTF-8
to_charsetstring

The file's new character set.

Any cPanel-supported character set encoding.ASCII