線上書籍

Home

XOOPS 模組開發

先在表單加入上傳物件:

//加入一個「上傳」文字框元件 $form->setExtra("enctype='multipart/form-data'"); $form->addElement(new XoopsFormFile('上傳', 'pic', '2048000'));

在新增或更新功能加入:

if(empty($honor_sn))$honor_sn=$xoopsDB->getInsertId(); if(!empty($_FILES['pic']['name'])){ include_once XOOPS_ROOT_PATH.'/class/uploader.php'; $allowed = array('image/jpg','image/jpeg'); $target = XOOPS_ROOT_PATH."/uploads/"; $uploader = new XoopsMediaUploader($target, $allowed, 2048000); $uploader->setTargetFileName("{$honor_sn}.jpg"); $uploader->fetchMedia('pic',0); $uploader->upload(); }

抓取圖檔資料:

if(file_exists(XOOPS_ROOT_PATH."/uploads/{$all['honor_sn']}.jpg")){ $all_data[$i]['pic']=true; }

樣板套用:

<{$if $h.pic}> <img src='<{$xoops_url}>/uploads/<{$h.pic}>.jpg' width=120> <{/if}>