Implement downloading of .log and .tma files

This commit is contained in:
Karsten Heiken
2011-10-15 13:44:40 +02:00
parent 72d80ea015
commit 29d9cdc831
2 changed files with 12 additions and 5 deletions

View File

@@ -87,8 +87,14 @@ class Results extends MY_Controller {
* Downloads the results of a given experiment. * Downloads the results of a given experiment.
* *
* @param string $experimentId * @param string $experimentId
* @param string $what
*/ */
public function download($experimentId = '') { public function download($experimentId = '', $what = 'out') {
// only allow download of specific files
if(!in_array($what, array('out', 'tma', 'log')))
show_404();
$job = $this->job->getByExperimentId($experimentId); $job = $this->job->getByExperimentId($experimentId);
if (empty($experimentId) || !$job) { if (empty($experimentId) || !$job) {
show_404(); show_404();
@@ -98,12 +104,12 @@ class Results extends MY_Controller {
$path = FCPATH.'uploads/'.$experiment['project_id'].'/'.$experiment['id'].'/'; $path = FCPATH.'uploads/'.$experiment['project_id'].'/'.$experiment['id'].'/';
if (file_exists($path.'default.out')) { if (file_exists($path.'default.'.$what)) {
// load download helper // load download helper
$this->load->helper('download'); $this->load->helper('download');
// download the file // download the file
$data = file_get_contents($path.'default.out'); $data = file_get_contents($path.'default.'.$what);
force_download('default.out', $data); force_download('default.'.$what, $data);
} }
} }
} }

View File

@@ -11,7 +11,8 @@
if (count($results) > 0): if (count($results) > 0):
?> ?>
<p> <p>
<a href="<?=site_url('results/download/'.$experiment['id']);?>" class="button download"><?=_('Download');?></a> <h4>Downloads results</h4>
<a href="<?=site_url('results/download/'.$experiment['id']).'/out';?>" class="button left download"><?=_('Results (.out)');?></a><a href="<?=site_url('results/download/'.$experiment['id']).'/tma';?>" class="button middle download"><?=_('T-Matrix (.tma)');?></a><a href="<?=site_url('results/download/'.$experiment['id']).'/log';?>" class="button right download"><?=_('Application output (.log)');?></a>
</p> </p>
<?php <?php
endif; endif;