Upload to BunnyCDN storage server using PHP

BunnyCDN storage servers are very affordable and work fast. You can fast track content delivery across the globe using them.

Whilst uploading file/s with FTP in a PHP script isn’t new or ground breaking it is easy implement with your storage block username and FTP password given in the BunnyCDN panel.

The full code is:

function uploadFTP($server, $username, $password, $file_to_upload, $save_file_as){
    $connection = ftp_connect($server);
    if (@ftp_login($connection, $username, $password)){
        // connection success
        return "Error connecting to $server";
    ftp_pasv($connection, true);
    ftp_put($connection, $save_file_as, $file_to_upload, FTP_BINARY);
    return "Uploaded $file_to_upload to $server and saved as $save_file_as";
//call to upload a file
uploadFTP("storage.bunnycdn.com", "USERNAME", "PASSWORD", "filetoupload.zip", "saveitas.zip");

Do note the ftp_pasv this had to be used as it enables passive FTP mode which suits the BunnyCDN connection.

Make sure you obviously change the USERNAME, PASSWORD and the file to upload and what to save it as in the BunnyCDN storage zone.