Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add function to make download file name original file name.
  • Loading branch information
kokoro912 committed Dec 5, 2018
1 parent c697e79 commit 91c661d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions Config/update.sql
Expand Up @@ -25,4 +25,5 @@ CREATE TABLE IF NOT EXISTS `ib_groups_courses` (
SET FOREIGN_KEY_CHECKS=1;

ALTER TABLE ib_courses ADD COLUMN introduction text AFTER title;
ALTER TABLE ib_contents ADD COLUMN file_name varchar(200) AFTER url;

5 changes: 5 additions & 0 deletions Controller/ContentsController.php
Expand Up @@ -289,6 +289,8 @@ public function admin_upload($file_type)
$fileUpload->setExtension($upload_extensions);
$fileUpload->setMaxSize($upload_maxsize);

$original_file_name = '';

if ($this->request->is(array(
'post',
'put'
Expand All @@ -299,6 +301,8 @@ public function admin_upload($file_type)

$fileUpload->readFile( $this->request->data['Content']['file'] ); // ファイルの読み込み

$original_file_name = $this->request->data['Content']['file']['name'];

$new_name = date("YmdHis").$fileUpload->getExtension( $fileUpload->get_file_name() ); // ファイル名:YYYYMMDDHHNNSS形式+"既存の拡張子"

$file_name = WWW_ROOT.DS."uploads".DS.$new_name; // ファイルのパス
Expand All @@ -320,6 +324,7 @@ public function admin_upload($file_type)

$this->set('mode', $mode);
$this->set('file_url', $file_url);
$this->set('file_name', $original_file_name);
$this->set('upload_extensions', join(', ', $upload_extensions));
$this->set('upload_maxsize', $upload_maxsize);
}
Expand Down
19 changes: 16 additions & 3 deletions View/Contents/admin_edit.ctp
Expand Up @@ -9,6 +9,12 @@
widht : 85%;
}

.form-control-filename
{
border : none !important;
box-shadow : none !important;
}

label span
{
font-weight: normal;
Expand Down Expand Up @@ -103,7 +109,7 @@
break;
}
}

function preview()
{
var content_kind = $('input[name="data[Content][kind]"]:checked').val();
Expand Down Expand Up @@ -131,10 +137,13 @@
}
});
}

function setURL(url)
function setURL(url, file_name)
{
$('.form-control-upload').val(url);

if(file_name)
$('.form-control-filename').val(file_name);
}
</script>
<?php $this->end(); ?>
Expand Down Expand Up @@ -169,6 +178,10 @@
echo "<div class='kind kind-movie kind-url kind-file'>";
echo $this->Form->input('url', array('label' => 'URL', 'class' => 'form-control form-control-upload'));
echo "</div>";

echo "<div class='kind kind-file'>";
echo $this->Form->input('file_name', array('label' => 'ファイル名', 'class' => 'form-control-filename', 'readonly' => 'readonly'));
echo "</div>";

echo "<div class='kind kind-text kind-html'>";
echo $this->Form->input('body', array('label' => '内容'));
Expand Down
5 changes: 3 additions & 2 deletions View/Contents/admin_upload.ctp
Expand Up @@ -12,11 +12,12 @@
{
var mode = '<?php echo $mode?>';
var file_url = '<?php echo $file_url?>';
var file_name = '<?php echo $file_name?>';

if(mode=='complete')
{
$('#btnUpload').hide();
opener.setURL(file_url);
opener.setURL(file_url, file_name);
window.close();
}
});
Expand All @@ -26,7 +27,7 @@
ファイルのアップロード
</div>
<div class="panel-body">
<div class="alert alert-warning">アップロードするファイルを指定して、アップロードボタンをクリックしてください。</div>
<div class="alert alert-warning">アップロードするファイルを指定して、アップロードボタンをクリックしてください。<br>ファイルが複数ある場合には、ZIP形式で圧縮してアップロードを行ってください。</div>
<div class="form-group">
<h4>アップロード可能拡張子</h4>
<?php echo $upload_extensions;?>
Expand Down
7 changes: 5 additions & 2 deletions View/Contents/index.ctp
Expand Up @@ -176,8 +176,11 @@
$title_link = $this->Html->link(
$content['Content']['title'],
$url,
array('target'=>'_blank'
));
array(
'target'=>'_blank',
'download' => $content['Content']['file_name']
)
);
break;
default : // その他(学習)
$icon = 'glyphicon glyphicon-play-circle text-info';
Expand Down

0 comments on commit 91c661d

Please sign in to comment.