Description

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

Examples




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

 



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



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



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



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



{  
   "messages":null,
   "errors":null,
   "status":1,
   "metadata":{  

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



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