다운로드(download) Sample

<?php
/**
 * Download helper
 *
 * Created on 2011. 11. 18.
 * @author 불의회상 <hoksi2k@hanmail.net>
 * @package helper
 * @subpackage controllers
 * @version 1.0
 */
class Download_hlp extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		
		// Cookie Helper Load
		$this->load->helper('download');
	}
	
	function index() {
		$data = '';
		$this->load->view('download_hlp_sample', $data);
	}

	function download()
	{
		$data = 'Here is some text!';
		$name = 'mytext.txt';

		force_download($name, $data);
	}
	
	function download_file()
	{
		$data = file_get_contents(FCPATH . "sample/images/mypic.jpg"); // Read the file's contents
		$name = 'myphoto.jpg';

		force_download($name, $data);
	}
}
<?php $this->load->view('inc/header')?>

<table class="tablesorter" border="0" cellpadding="0" cellspacing="1">
<thead>
<tr>
  <th style="text-align:center" colspan="2">Download Helper</th>
</tr>
</thead>
<tr>
	<td width="20%">Download Test</td>
	<td>
		<input type="button" value="text Download" onclick="document.location.href = '<?=site_url('download_hlp/download')?>'" />
		<input type="button" value="file Download" onclick="document.location.href = '<?=site_url('download_hlp/download_file')?>'" />
	</td>
</tr>
</table>

<?php $this->load->view('inc/footer')?>

© Copyright by hoksi(Page rendered in 0.0065 seconds)