Tag Archive: blueline

File downlaod using CodeIgniter

CodeIgniter has a nice helper class to download files. Its a nice way to download from server without any hassle just writing one single controller function.

public function download ($file_path = "")
			$this->load->helper('download'); //load helper
			//$file_path = $this->input->post("file_path",TRUE);
			$layout="no_theme"; //if you have layout
			$data['download_path'] = $file_path;		
			$this->load->view("view file",$data);
			redirect("same url", "refresh");						

In view section, just call the download function thats it.

	if( ! empty($download_path))
		$data = file_get_contents(base_url() ."/...path.../".$download_path); // Read the file's contents
		$name = $download_path;

		force_download($name, $data);


Its the most simple process to download using CodeIgniter


URL Shortening using bit.ly

The bit.ly API allows developers to interact in a programmatic way with the bit.ly website. The current API version is 2.0.1.
It’s a very simple way to shorten the URL through bit.ly API.

     * Function: URL_shortener
     * @description : Create a shorten URl from a long URL
     * @param  $ : $url
     * @return : none
     * @author : sumon.
     * @last -modified-by: sumon.

	function URL_shortener($url ="")
		$api_data = file_get_contents("http://api.bit.ly/shorten?version=2.0.1&longUrl=".$url."&login=bitlyapidemo&apiKey=R_0da49e0a9118ff35f52f629d2d71bf07");
		$array_data = json_decode($api_data);
		$result = $array_data->results;
		foreach($result as $results)
			$short_url = $results->shortUrl;
		return $short_url;

It’s too simple to call that API. 🙂