Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Download movies and/or episodes works now
- Loading branch information
Showing
8 changed files
with
230 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
class Files extends CI_Controller | ||
{ | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
|
||
// Chargement des modèles de la base de données 'xbmc_video' | ||
$this->load->model('video/actors_model'); | ||
$this->load->model('video/countries_model'); | ||
$this->load->model('video/episodes_model'); | ||
$this->load->model('video/video_files_model'); | ||
$this->load->model('video/genres_model'); | ||
$this->load->model('video/movies_model'); | ||
$this->load->model('video/video_paths_model'); | ||
$this->load->model('xbmc/sources_model'); | ||
$this->load->model('video/sets_model'); | ||
$this->load->model('video/studios_model'); | ||
$this->load->model('video/tvshows_model'); | ||
} | ||
|
||
/** | ||
* Demande à télécharger un film ou un épisode | ||
*/ | ||
public function ajax_download() | ||
{ | ||
// L'utilisateur connecté peut télécharger des vidéos ? | ||
if ($this->session->userdata('can_download_video')) | ||
{ | ||
// Champ concerné par la modification | ||
list($type, $id) = explode('_', $this->uri->segments[3]); | ||
|
||
switch($type) | ||
{ | ||
case 'movie': | ||
$files = $this->movies_model->get($id, FALSE); | ||
$filename = $files[0]->filename; | ||
$path = str_replace($files[0]->source->client_path, $files[0]->source->server_path, $files[0]->path); | ||
break; | ||
|
||
case 'episode': | ||
$files = $this->episodes_model->get($id, FALSE); | ||
$filename = $files[0]->filename; | ||
$path = str_replace($files[0]->source->client_path, $files[0]->source->server_path, $files[0]->path); | ||
break; | ||
} | ||
|
||
// Chargement de la focntion 'force_download' | ||
$this->load->helper('MY_download'); | ||
|
||
// Force le téléchargement du fichier | ||
force_download($filename, $path.$filename); | ||
} | ||
|
||
// Sortie avec téléchargement de fichier ou pas | ||
die(); | ||
} | ||
|
||
} | ||
|
||
/* End of file files.php */ | ||
/* Location: ./system/application/controllers/files.php */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | ||
/** | ||
* Force Download | ||
* | ||
* Generates headers that force a download to happen | ||
* | ||
* @access public | ||
* @param string filename | ||
* @param mixed the data to be downloaded | ||
* @return void | ||
*/ | ||
if ( ! function_exists('force_download')) | ||
{ | ||
function force_download($filename = '', $file = '') | ||
{ | ||
if ($filename == '' OR $file == '') | ||
{ | ||
return FALSE; | ||
} | ||
|
||
// Try to determine if the filename includes a file extension. | ||
// We need it in order to set the MIME type | ||
if (FALSE === strpos($filename, '.')) | ||
{ | ||
return FALSE; | ||
} | ||
|
||
// Grab the file extension | ||
$x = explode('.', $filename); | ||
$extension = end($x); | ||
|
||
// Load the mime types | ||
@include(APPPATH.'config/mimes'.EXT); | ||
|
||
// Set a default mime if we can't find it | ||
if ( ! isset($mimes[$extension])) | ||
{ | ||
$mime = 'application/octet-stream'; | ||
} | ||
else | ||
{ | ||
$mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; | ||
} | ||
|
||
// Generate the server headers | ||
if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE") !== FALSE) | ||
{ | ||
header('Content-Type: "'.$mime.'"'); | ||
header('Content-Disposition: attachment; filename="'.$filename.'"'); | ||
header('Expires: 0'); | ||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | ||
header("Content-Transfer-Encoding: binary"); | ||
header('Pragma: public'); | ||
header("Content-Length: ".filesize($file)); | ||
} | ||
else | ||
{ | ||
header('Content-Type: "'.$mime.'"'); | ||
header('Content-Disposition: attachment; filename="'.$filename.'"'); | ||
header("Content-Transfer-Encoding: binary"); | ||
header('Expires: 0'); | ||
header('Pragma: no-cache'); | ||
header("Content-Length: ".filesize($file)); | ||
} | ||
|
||
readfile_chunked($file); | ||
die; | ||
} | ||
} | ||
|
||
/** | ||
* readfile_chunked | ||
* | ||
* Reads file in chunks so big downloads are possible without changing PHP.INI | ||
* | ||
* @access public | ||
* @param string file | ||
* @param boolean return bytes of file | ||
* @return void | ||
*/ | ||
if ( ! function_exists('readfile_chunked')) | ||
{ | ||
function readfile_chunked($file, $retbytes=TRUE) | ||
{ | ||
$chunksize = 1 * (1024 * 1024); | ||
$buffer = ''; | ||
$cnt =0; | ||
|
||
$handle = fopen($file, 'r'); | ||
if ($handle === FALSE) | ||
{ | ||
return FALSE; | ||
} | ||
|
||
while (!feof($handle)) | ||
{ | ||
$buffer = fread($handle, $chunksize); | ||
echo $buffer; | ||
ob_flush(); | ||
flush(); | ||
|
||
if ($retbytes) | ||
{ | ||
$cnt += strlen($buffer); | ||
} | ||
} | ||
|
||
$status = fclose($handle); | ||
|
||
if ($retbytes AND $status) | ||
{ | ||
return $cnt; | ||
} | ||
|
||
return $status; | ||
} | ||
} | ||
|
||
/* End of file MY_download_helper.php */ | ||
/* Location: ./application/helpers/MY_download_helper.php */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<button id="download-button" class="button" type="button"> | ||
<img src="<?php echo base_url(); ?>assets/gui/download.png" /> <?php echo $this->lang->line('btn_download'); ?> | ||
</button> | ||
<img src="<?php echo base_url(); ?>assets/gui/download.png" /> <?php echo $this->lang->line('btn_download'); ?> | ||
</button> | ||
<iframe id="download_frame" name="uploadFrame" src="#" style="display:none;"></iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
jQuery(document).ready(function() { | ||
|
||
// Attache le téléchargement d'un film ou d'un épisode | ||
$("#download-button").click(function(){ | ||
$("#download_frame").attr("src",site_url+"files/download/"+media_id); | ||
return false; | ||
}); | ||
|
||
}); |