Child pages
  • UAPI Functions - Fileman::save_file_content

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

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

Multiexcerpt include
SpaceWithExcerptcom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@12665
MultiExcerptNameAPIDisabledFileStorageRole
PageWithExcerptLIB:_ServerRoleDisabledAPI

Panel
bgColor#F2F2F2
borderStylenone

Examples


Panel
bgColor#FFFFFF
borderStylenone


Expand
titlecPanel or Webmail Session URL


Code Block
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

 

Include Page
LIB:_CallUAPIFromBrowserLink
LIB:_CallUAPIFromBrowserLink


Expand
titleLiveAPI PHP Class


Code Block
languagephp
linenumberstrue
$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',
 )
);

Include Page
LIB:_LiveAPIPHPLink
LIB:_LiveAPIPHPLink


Expand
titleLiveAPI Perl Module


Code Block
languageperl
linenumberstrue
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',
		}
 );

Include Page
LIB:_LiveAPIPerlLink
LIB:_LiveAPIPerlLink


Expand
titlecPanel Template Toolkit


Code Block
languagexml
linenumberstrue
<!-- 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 %]

Include Page
LIB:_TTLink
LIB:_TTLink


Expand
titleCommand Line


Code Block
languagebash
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

Include Page
LIB:_UAPICLINote
LIB:_UAPICLINote


Expand
titleOutput (JSON)


Code Block
languagetext
linenumberstrue
{  
   "messages":null,
   "errors":null,
   "status":1,
   "metadata":{  

  },
  "data": {
    "from_charset": "utf-8",
    "to_charset": "utf-8",
    "path": "/home/username/public_html/example.html"
  }
}


Include Page
LIB:_cPanelAPIShellNote
LIB:_cPanelAPIShellNote


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