• 06-09-2023, 17:25:59
    #1
    Merhaba herkese, Cpanel hesabıma cpanel api ile dosya yükleyen bir koda sahibim. kod sorunsuz çalışıyor. Ancak Yükleyeceğim dosya cpanel file managerda ZATEN varsa yüklenmiyor. Bu dosyanın üzerine yazılmasını ya da önceki dosyanın silinip yeni dosyanın yüklenmesini istiyorum arkadaşlar acaba nasıl yapabilirim yardımlarını bekliyorum..

    İlgili kod:
    <?php
    // Log everything during development.
    // If you run this on the CLI, set 'display_errors = On' in php.ini.
    error_reporting(E_ALL);
    // Declare your username and password for authentication.
    $username = 'xxxxx';
    $password = 'xxxxx';
    // Define the API call.
    $cpanel_host = 'xxxxxx';
    $request_uri = "https://$cpanel_host:2083/execute/Fileman/upload_files";
    // Define the filename and destination.
    $upload_file = realpath("test.php");
    $destination_dir = "public_html";
    // Set up the payload to send to the server.
    if( function_exists( 'curl_file_create' ) ) {    $cf = curl_file_create( $upload_file ); } else {    $cf = "@/".$upload_file; }
    $payload = array(    'dir'    => $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 ) );
    ?>
  • 06-09-2023, 17:30:52
    #2
    payloadınıza
    'overwrite' => 1,
    eklemeniz yeterli hocam. (kaynak: ChatGPT)
  • 06-09-2023, 17:51:05
    #3
    Pandora01 adlı üyeden alıntı: mesajı görüntüle
    payloadınıza
    'overwrite' => 1,
    eklemeniz yeterli hocam. (kaynak: ChatGPT)
    Evet çalıştı hocam teşekkürler. Acaba Chatgpt ne diye sordunuz bir de chatgpt hangi sürümü hocam?
  • 06-09-2023, 17:53:41
    #4
    pess1nu5 adlı üyeden alıntı: mesajı görüntüle
    Evet çalıştı hocam teşekkürler. Acaba Chatgpt ne diye sordunuz bir de chatgpt hangi sürümü hocam?
    düz 3.5 versiyonu.
    direkt kodu attım enter bastım tabii kodun ne yaptığını söyledi sonra ona cevap olarak da
    "it doesnt upload a file if it is already present on the remote side. can u make it so it overwrites it instead"
    dedim ve bana düzenlenmiş kodu attı.
  • 06-09-2023, 17:54:42
    #5
    Pandora01 adlı üyeden alıntı: mesajı görüntüle
    düz 3.5 versiyonu.
    direkt kodu attım enter bastım tabii kodun ne yaptığını söyledi sonra ona cevap olarak da
    "it doesnt upload a file if it is already present on the remote side. can u make it so it overwrites it instead"
    dedim ve bana düzenlenmiş kodu attı.
    Anladım tekrardan teşekkür ederim hocam..