UAPI Functions - Fileman::save_file_content

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

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

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

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

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

 

Parameters

 Parameters 

Type

Description

Possible values

Example

dir

string

The directory that contains the selected file.

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

A valid directory name.

public_html

file

string

Required

The files to retrieve.

A valid filename.

 example.html 

from_charset

string

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

This parameter defaults to UTF-8.

Any cPanel-supportedcharacter encoding.

UTF-8

to_charset

string

The character set encoding in which to encode the file.

This parameter defaults to UTF-8.

Any cPanel-supportedcharacter encoding.

ASCII

content

string

The new file's contents.

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

A string value.

hi

fallback

 Boolean 

 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

Return

Type

Description

Possible values

Example

path

string

The path to the file.

A valid absolute file path.

 /home/user/public_html/example.html 

 from_charset 

string

The file's character set.

Any cPanel-supported character set encoding.

UTF-8

   to_charset

 string 

 The file's new character set. 

 Any cPanel-supported character set encoding. 

ASCII

 

  • 0 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....