dungadeptry

Registered
Feb 8, 2022
1
0
1
Việt Nam
cPanel Access Level
Root Administrator
{"cpanelresult": {"postevent": {"result": 1}, "apiversion": 2, "error": "You must only be only one file to upload.", "preevent": {"result ": 1}," data ": [{" fail ": 0," warning ": 0," success ": 0," uploads ": []}]," func ":" uploadfiles "," event ": {"result": 1}, "module": "Fileman"}}


PHP:
<?php
header('Content-Type: application/json');

if ($_GET['user'] && $_GET['pass'] && $_GET['domain'] && $_GET['host']) {
    $cpanelusername = $_GET['user'];        // TK CPANEL
    $cpanelpassword = $_GET['pass'];        // MK CPANEL
    $domain = $_GET['domain'];              // USERDATABASE
    $host = $_GET['host'];                  // HOST
    $directory = "/public_html/$domain";    // FOLDER
    $file = "myfile.html";
    $query = "https://$host/json-api/cpanel?cpanel_jsonapi_user=user&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=Fileman&cpanel_jsonapi_func=uploadfiles&dir=$directory&file-=file1-myfile.txt";

    $curl = curl_init();                                // Create Curl Object
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);       // Allow self-signed certs
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);       // Allow certs that do not match the hostname
    curl_setopt($curl, CURLOPT_HEADER, 0);               // Do not include header in output
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);       // Return contents of transfer on curl_exec
    $header[0] = "Authorization: Basic " . base64_encode($cpanelusername . ":" . $cpanelpassword) . "\n\r";
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);    // set the username and password
    curl_setopt($curl, CURLOPT_URL, $query);            // execute the query
    $result = curl_exec($curl);
    if ($result == false) {
        error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
    }
    curl_close($curl);
    $myfile = fopen("hostfree.txt", "w");
    $hostfree = "username => $cpanelusername | password => $cpanelpassword | host => $host\n";
    fwrite($myfile, $hostfree);
    fclose($myfile);
   
    print $result;
} else {
    echo json_encode(array("status" => "error", "message" => "Thiếu dữ liệu tải lên", "author" => "DUNGA"));
}
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
11,638
1,847
363
cPanel Access Level
Root Administrator
Hey there! Debugging PHP is beyond the scope of our support team, both through the Forums and through our support tickets. However, if you're seeing issues with the isolated API call I'd be happy to do some testing with that.

We do have an example Perl and PHP script for this function in our documentation here:


so if a specific piece of that example isn't working I'd be happy to check that.