cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Download file question

From: Rob Round <rob_at_pointvisionweb.com>
Date: Wed, 16 Nov 2005 09:52:45 -0500

Hi Folks,

I'm trying to make a very simple script for downloading a daily backup from
a cpanel account.

This is what I have so far:

set_time_limit(240);

$domain = 'domain.com';
$user = 'username';
$pass = 'password';

function getByCurl($url, $user = '', $pass = '')
{
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");

        $result = curl_exec($ch);
        curl_close($ch);

        return $result;
}

function downloadBackup(&$backup, $filename)
{
        header("Content-type: application/x-zip");
        //header("Content-type: application/x-msdownload");
        header("Content-Disposition: attachment; filename=$filename");
        header("Pragma: no-cache");
        header("Expires: 0");
        print $backup;

        return;
}

if (!extension_loaded('curl'))
{
        dl('php_curl.' .PHP_SHLIB_SUFFIX) or die("Could not load curl extension");
}

$protocol = 'http://';
$cpPort = '2082';

$filename = '';
$siteBackup = '';
$filename = 'backup-'. $domain . '-' . date('n-j-Y') . '.tar.gz';

$siteBackup = getByCurl($protocol . 'www' . $domain . ':' . $cpPort .
'/getbackup/' . $filename,$user,$pass);

downloadBackup($siteBackup, $filename);

The problem seems to be in the getByCurl function and I cannot seem to get
beyond this code as is and $result never gets returned. If I comment out:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

I have the contents of the file displayed to the screen so I know I am
getting to the file I want to download. I just want the resulting file
contents to be assigned to $result so I can return it and pass it to the
download function.

Any help appreciated.

Thanks,
Rob.

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2005-11-16