這篇文章主要介紹“如何用CMS上傳文件到指定位置并固定命名”,在日常操作中,相信很多人在如何用CMS上傳文件到指定位置并固定命名問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”如何用CMS上傳文件到指定位置并固定命名”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專(zhuān)注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、重慶小程序開(kāi)發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了都安免費(fèi)建站歡迎大家使用!
上傳文件到指定的目錄命名,比如我需要上傳一個(gè)文件到/cache/my.txt,固定的位置,固定的命名。
1、創(chuàng)建控制器:/dayrui/App/Demo/Controllers/Upload.php
<?php namespace Phpcmf\Controllers\Admin;
class Upload extends \Phpcmf\Common
{
// 上傳界面
public function index() {
\Phpcmf\Service::V()->assign('upload_url', dr_url('demo/upload/add'));
\Phpcmf\Service::V()->display('upload.html');
}
// 上傳處理
function add() {
$file = WRITEPATH.'my.txt';
$rt = \Phpcmf\Service::L('upload')->upload_file([
'save_file' => $file, // 上傳的固定文件路徑
'form_name' => 'file_data', // 固定格式
'file_exts' => ['txt'], // 上傳的擴(kuò)展名
'file_size' => 10 * 1024 * 1024, // 上傳的大小限制
'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info('null'), // 固定文件時(shí)必須這樣寫(xiě)
]);
if (!$rt['code']) {
// 失敗了
exit(dr_array2string($rt));
}
// 上傳成功了
exit(dr_array2string($rt));
}
}2、創(chuàng)建模板文件:/dayrui/App/Demo/Views/upload.html
{template "header.html"}
<link href="{ROOT_THEME_PATH}assets/global/plugins/jquery-fileupload/css/jquery.fileupload.css" rel="stylesheet" type="text/css" />
<script src="{ROOT_THEME_PATH}assets/global/plugins/jquery-fileupload/js/jquery.fileupload.js" type="text/javascript"></script>
<div class="dev" id="fileupload">
<a href="___JavaScript:;" class="fileinput-button btn read"> <i class="fa fa-upload"></i> {dr_lang('上傳文件')}<input type="file" name="file_data"> </a>
</div>
<script type="text/javascript">
$(function() {
$("#fileupload").fileupload({
disableImageResize: false,
autoUpload: true,
maxFileSize: "10000000000",
url: "{$upload_url}",
dataType: "json",
acceptFileTypes: "*",
maxChunkSize: 0,
progressall: function (e, data) {
// 上傳進(jìn)度條 all
},
add: function (e, data) {
$(".fileupload-progress").hide();
data.submit();
},
done: function (e, data) {
if (data.result.code > 0) {
dr_tips(data.result.code, data.result.msg);
} else {
dr_tips(data.result.code, data.result.msg, -1);
}
},
fail: function (e, data) {
//console.log(data.errorThrown);
dr_tips(0, "系統(tǒng)故障:"+data.errorThrown, -1);
layer.closeAll('tips');
},
});
});
</script>
{template "footer.html"}3、訪問(wèn)上傳界面:
/admin.php?s=demo&c=upload&m=index
到此,關(guān)于“如何用CMS上傳文件到指定位置并固定命名”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
名稱(chēng)欄目:如何用CMS上傳文件到指定位置并固定命名
分享地址:http://chinadenli.net/article36/ghodpg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、小程序開(kāi)發(fā)、面包屑導(dǎo)航、網(wǎng)站營(yíng)銷(xiāo)、服務(wù)器托管、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)