cPanel API 2 Functions - Fileman::savefile

Description

This function saves a string to a file.

Warning:

This function is deprecated as of cPanel version 11.40+. We strongly recommend that you use the following UAPIfunction instead of this function:
  • Fileman::save_file_content — This function saves a file in a directory and encodes it in a character set.

Examples 


 WHM API (JSON)

https://hostname.example.com:2087/cpsess##########/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Fileman&cpanel_jsonapi_func=savefile&path=home%2Fexample&filename=new_file&content=This%20is%20a%20saved%20string.

 LiveAPI PHP Class

$cpanel new CPANEL(); // Connect to cPanel - only do this once.
  
// Create a directory.
$mkdir $cpanel->api2(
    'Fileman''savefile'
        array(
        "path"             =>       "/home/example",
        "filename"          =>       "new_file",
        "content"           =>       "This is a saved string."
        )
);

 LiveAPI Perl Module

my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.
  
# Create a file.
my $savefile $cpliveapi->api2(
    'Fileman''savefile',
      {
        "path"              =>       "/home/example",
        "filename"          =>       "new_file",
        "content"           =>       "This is a saved string."
      }
 );

 cPanel Tag System (deprecated)

Warning:

In cPanel & WHM version 11.30 and later, cPanel tags are deprecated. We strongly recommend that youonly use the LiveAPI system to call the cPanel APIs.

cPanel API 2 calls that use cPanel tags vary widely in code syntax and in their output. For more information, read our Deprecated cPanel Tag Usage documentation. Examples are only present in order to help developers move from the old cPanel tag system to our LiveAPI.

 

 Command Line

cpapi2 --user=username Fileman savefile path=%2Fhome%2Fexample filename=new_file content="This is a saved string."

 

Notes:

  • You must URI-encode values.
  • username represents your account-level username.

 Output (JSON)

{
  "cpanelresult": {
    "apiversion": 2,
    "func": "savefile",
    "data": [
      {
        "path": "/home/example/new_file",
        "charset": "utf-8"
      }
    ],
    "event": {
      "result": 1
    },
    "module": "Fileman"
  }
}

Note:

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

 

Parameters

 Parameter 

 Type

Description

Possible values

Example

 path

 string 

 Required

 The new file's path.

 A valid absolute file path. 

 /home/user

 filename

 string

 Required

 The new file's name.

 A valid file name.

 new_file.txt

 content

 string

 Required

 The new file's contents.

 A valid string.

 This is saved content. 

 charset

 string

 The new file's character set.

 This parameter defaults to utf-8.

 Warning: 

 We strongly recommend that you do not use this parameter. 

 A valid character set.

 utf-32

   

Returns

 Return 

Type

Description

Possible values

Example

 charset

 string

 The file's character set.

 The charset input parameter's value. 

 utf-8  

 path

 string

 The file's path.

 A valid absolute file path.

 /home/example/new_file 

 reason

 string

 A reason for failure

 Note:

 This function only returns a reasonvalue if an error occurred. 

 A string that describes the error.

 This is an error message.

 result

 Boolean 

 Whether the function succeeded.

  • 1 — The function succeeded.
  • 0 — The function failed.

 1

 

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