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

 

Description

This function uploads files.

Note:

For more information about how to use this function in your custom code, read our Use UAPI's Fileman::upload_files Function in Custom Code tutorial.

Examples


 cPanel or Webmail Session URL
https://hostname.example.com:2083/cpsess##########/execute/Fileman/upload_files?dir=/home/user/public_html&file-1=example.html&file-2=rankand.html

 

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.
 
// Upload files to public_html directory.
$upload_files = $cpanel->uapi(
    'Fileman', 'upload_files',
		array(
		'dir'			    => '/home/user/public_html',
		'file-1'			=> 'nail.html',
		'file-2'			=> 'rankand.html',
		 )
);

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.
 
# Upload files to public_html directory.
my $ upload_files = $cpliveapi->uapi(
 	'Fileman', 'upload_files',
		{
		'dir'			    => 'public_html',
		'file-1'			=> 'nail.html',
		'file-2'			=> 'rankand.html',	
		 }
 );

Note:

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

 

 cPanel Template Toolkit
<!-- Get a hash of all the data, then display the uploads value. -->
[% data = execute( 'Fileman', 'upload_files' {dir => 'public_html, 'file' => 'example.html' ); %]
[% FOREACH q = data.prefix %]
     <p>
         [% q %]
     </p>
[% END %]
 
<!-- Get only a hash of the data. -->
[% execute('Fileman', 'upload_files' {dir => 'public_html, 'file-1' => 'nail.html', 'file-2' => 'rankand.html'}  ).data.uploads %]

Note:

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

 

 Command Line
uapi --user=username Fileman upload_files dir=%2Fhome%2Fusername%2Fpublic_html file-1=example.html file-2=rankand.html

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": {
    "uploads": [
      nail.html
	  rankand.html	
    ],
    "succeeded": 2,
    "warned": 0,
    "failed": 0
  }
}


Note:

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

 

Parameters

ParametersTypeDescriptionPossible valuesExample
dirstring

Required

The directory to which to upload the files.

A valid directory on the server, relative to the user's home directory.public_html
file-*string

Required

The files to upload.

Important:

  • You must pass this parameter for each file to upload.
  • You must increment each variable. For example, pass the first file as file-1 and the second file as file-2.
A valid filename on the server.nail.html

Returns

ReturnTypeDescriptionPossible valuesExample
uploadsarray

A list of files that uploaded to the specified directory.

A list of upload files.example.html
succeededintegerThe number of files that uploaded successfully.A positive integer.1
warnedintegerThe number of files that did not fully upload.A positive integer.0
failedintegerThe number of files that failed to upload.A positive integer.0