Skip to main content
cPanel Technical Support has been heavily impacted by hurricane Beryl and our ability to respond to tickets has been hindered as a result. We appreciate your understanding and patience as we address these delays.

Comments

16 comments

  • cPanelMichael
    Hello, You will need to adjust your custom script so that it follows the guide and example we document at: Tutorial - Use UAPI's Fileman::upload_files Function in Custom Code - Developer Documentation - cPanel Documentation Let us know if this helps. Thank you.
    0
  • Marani
    Hello, You will need to adjust your custom script so that it follows the guide and example we document at:
    0
  • cPanelMichael
    The thing is, I want to upload a ready file. I mean in number 11 the content is getting put inside the file, but mine is a ready-to-upload file on the computer. I need to use variable inside programming code or upload the file from a local path.

    Hello, Step number four on the "PHP" example shows how to define the file to upload as a local path. Let me know if that helps. Thank you.
    0
  • Marani
    Hi, Thanks for helping Michael. Gave it a try and it's still the same. actually, that was what I inserted already. I even used a sniffer to capture the requests when uploading using cPanel as normal, and in the sniffer it was the same request I posted before. The POST request is correct that's strange it always returns this error?
    0
  • cPanelMichael
    Hello @Marani, I created a PHP script on a cPanel server matching the example referenced
    0
  • Marani
    Hi, I'm taking these steps:
    0
  • cPanelMichael
    Hello @Marani, Can you confirm that the local file you are uploading exists on the same machine that you are running the custom application on? If so, can you try setting up the PHP script referenced in our documentation (either locally or on the cPanel server) and then attempting to upload the same file? This way we can rule out if it's an issue with your custom application or if it's some other issue with the file upload process. Thank you.
    0
  • Marani
    Hello @Marani, Can you confirm that the local file you are uploading exists on the same machine that you are running the custom application on? If so, can you try setting up the PHP script referenced in our documentation (either locally or on the cPanel server) and then attempting to upload the same file? This way we can rule out if it's an issue with your custom application or if it's some other issue with the file upload process. Thank you.

    Hi Michael, sorry I've been so busy I couldn't come back and answer. I just tried what you said here is the result: On local using xampp installation it says: The cURL call did not return valid JSON: Fatal error: in C:\xampp\htdocs\uploadtest.php on line 49
    Line 49: die( $response ); And uploading the file on the server returns error 500: This page isn"t working mysite.com is currently unable to handle this request. HTTP ERROR 500 But the site itself works, it shows up with no error. Here the PHP code I tool from the sample link: [PHP] $destination_dir, 'file-1' => $cf ); // Set up the cURL request object. $ch = curl_init( $request_uri ); curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); curl_setopt( $ch, CURLOPT_USERPWD, $username . ':' . $password ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); // Set up a POST request with the payload. curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); // Make the call, and then terminate the cURL caller object. $curl_response = curl_exec( $ch ); curl_close( $ch ); // Decode and validate output. $response = json_decode( $curl_response ); if( empty( $response ) ) { echo "The cURL call did not return valid JSON:\n"; die( $response ); } elseif ( !$response->status ) { echo "The cURL call returned valid JSON, but reported errors:\n"; die( $response->errors[0] . "\n" ); } // Print and exit. die( print_r( $response ) ); ?>[/PHP] Any ideas? Thanks, Mehdi
    0
  • cPanelMichael
    Hello Mehdi, Let's start with the example you uploaded to the cPanel server so we can ensure it's working as expected.
    // Define the filename and destination. $upload_file = realpath("/favicon.ico"); $destination_dir = "public_html";

    Can you try using a file path accessible to the user you are logged in as? For example, try: $upload_file = realpath("/home/user123/favicon.ico");
    Make sure /home/user123/favicon.ico exists before executing the PHP script. If the "500" error code persists when running the code in your web browser, let us know the output to /usr/local/apache/logs/error_log when you see the error. Thank you.
    0
  • Marani
    Hi Michael, Tell me something, by "/home/user123/favicon.ico" do you mean cPanel path? because I want to upload from my computer to cPanel. [PHP]// Define the filename and destination. $upload_file = realpath("file.txt"); $destination_dir = "public_html";[/PHP] The cURL call returned valid JSON but reported errors: Failed to upload any of the requested files with various failures.
    0
  • cPanelMichael
    Tell me something, by "/home/user123/favicon.ico" do you mean cPanel path? because I want to upload from my computer to cPanel.

    Yes, for the purpose of this test you should use a path under the account on the cPanel server. A local path is only suitable when the script is hosted on your local computer (we are testing the script on the cPanel server first to rule out any issues with the API function itself on your system). Thank you.
    0
  • Marani
    /home/myUserName/file.txt returns: The cURL call did not return valid JSON but just file.txt returns what I mentioned last time: The cURL call returned valid JSON but reported errors: Failed to upload any of the requested files with various failures.
    0
  • Marani
    Ok Michael! I changed the destination_dir and now it says: stdClass Object ( [errors] => [messages] => [data] => stdClass Object ( [uploads] => Array ( [0] => stdClass Object ( [status] => 1 [size] => 0 [warnings] => Array ( ) [file] => file.txt [reason] => Upload of "file.txt" succeeded. ) ) [failed] => 0 [warned] => 0 [succeeded] => 1 ) [warnings] => [metadata] => stdClass Object ( ) [status] => 1 ) 1
    And I see the file has been copied to the new location I specified. It worked yes!?
    0
  • cPanelMichael
    Hello @Marani, Yes, the output you provided shows the file was successfully uploaded. This shows the API function is working as intended, and the reason your custom application is failing is likely the result of a coding error. I believe the primary issue is that you are attempting to upload a file from your local computer as opposed to a file that's stored on the cPanel server. For instance, in the
    0
  • Marani
    So you say uploading file to cPanel using API is not possible? I believe for developers this is one of those most-wanted features. And what's the reason to upload a file which already exists in cPanel via this API? is this a replacement for like, Copy command? What if I use POST and GET Requests to process it in the background instead of using APIs? would it work? I want to create a simple uploader command for my clients.
    0
  • cPanelMichael
    Hello @Marani, I apologize, I probably wasn't clear enough in my prior response. To clarify, the file itself doesn't have to exist on the cPanel server beforehand, but the UAPI function needs to receive the data associated with the file before the upload occurs. You can't enter the path to the file on your local workstation without first coding some method of sending the file data to the server. For instance, cURL is a common method of doing this with PHP when setting up a web page with a form that allows users to upload a file: Tutorial - Use UAPI's Fileman::upload_files Function in Custom Code - Developer Documentation - cPanel Documentation I don't have a specific C# example to provide, but here's a StackOverflow thread that may point you in the right direction:
    0

Please sign in to leave a comment.