/** * Downloads a url to a local temporary file using the NXTClass HTTP Class. * Please note, That the calling function must unlink() the file. * * @since 2.5.0 * * @param string $url the URL of the file to download * @param int $timeout The timeout for the request to download the file default 300 seconds * @return mixed nxt_Error on failure, string Filename on success. */ function download_url($url, $timeout = 300) { //WARNING: The file is not automatically deleted, The script must unlink() the file. if (!$url) { return new nxt_Error('http_no_url', __('Invalid URL Provided.')); } $tmpfname = nxt_tempnam($url); if (!$tmpfname) { return new nxt_Error('http_no_file', __('Could not create Temporary file.')); } $response = nxt_remote_get($url, array('timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname)); if (is_nxt_error($response)) { unlink($tmpfname); return $response; } if (200 != nxt_remote_retrieve_response_code($response)) { unlink($tmpfname); return new nxt_Error('http_404', trim(nxt_remote_retrieve_response_message($response))); } return $tmpfname; }
function put_contents($file, $contents, $mode = false) { $tempfile = nxt_tempnam($file); $temp = fopen($tempfile, 'w+'); if (!$temp) { return false; } fwrite($temp, $contents); fseek($temp, 0); //Skip back to the start of the file being written to $type = $this->is_binary($contents) ? FTP_BINARY : FTP_ASCII; $ret = @ftp_fput($this->link, $file, $temp, $type); fclose($temp); unlink($tempfile); $this->chmod($file, $mode); return $ret; }