/** * Download a File * * @param urld - required - * The download URL. * @param dir - required - * The download folder (path+folderName). * @param password - optional - * If a password has been set, the recipients are asked to enter the password before they can access the files. The minimum length of the password is 5 characters. * @return The status "fail" if the download has failed or the downloaded file name if the download has succeeded. * */ public function downloadaFile($urld, $dir, $password = '') { $parameters = array(); if ($password !== '') { $parameters['password'] = $password; } $a = new DownloadFile($this->_hostName, $this->_apiKey, $this->_userAgent); $response = $a->sendRequest($urld, $parameters, $this->_authToken); if ($response !== 'fail') { list($header, $h1, $body) = explode("\r\n\r\n", $response); $s = strpos($header, "&file=") + 6; $e = strpos($header, "Server:") - 2; $d = $e - $s; $fname = substr($header, $s, $d); $fname = urldecode($fname); $f = $dir . $fname; file_put_contents($f, $body); return $fname; } else { return 'fail'; } }