如何使用 php 在 key cdn 上传图片?

how to upload image in key cdn using php?

我想在我的站点上传每张图片时使用 php 在 keycdn 中上传图片。

选项可用 rsync 或 ftp 但它对我没有用。

所以,你能帮我直接使用 php 吗?

我认为你应该通过这个技巧来达到你的目的。

直接没有任何可用的方法,但通过 ftp 使用 PHP 是可能的。

<?php

function uploadFTP($server, $username, $password, $local_file, $remote_file){
    // connect to server
    $connection = ftp_connect($server);

    // login
    if (@ftp_login($connection, $username, $password)){
        // successfully connected
    }else{
        return false;
    }

    ftp_put($connection, $remote_file, $local_file, FTP_BINARY);
    ftp_close($connection);
    return true;
}

uploadFTP("ftp.keycdn.com", "yourusername", "yourpassword", "test.jpg", "/cdn/test.jpg");
?>