Exemplo n.º 1
0
 /**
  * 清除今日以前的临时文件
  *
  */
 public function clean()
 {
     if ($this->isPost() && $this->isAjax()) {
         if (C('TOKEN_ON') && !checkFormToken($_POST)) {
             die('hack attemp.');
         }
         @set_time_limit(3600);
         if (function_exists('ini_set')) {
             ini_set('max_execution_time', 3600);
             ini_set("memory_limit", "256M");
         }
         $localTimeObj = LocalTime::getInstance();
         $today = $localTimeObj->local_strtotime(date('Y-m-d 00:00:00'));
         $upload_path = DOC_ROOT_PATH . get_upload_path();
         $dir = $upload_path . 'temp/';
         $dirhandle = opendir($dir);
         while (($file = readdir($dirhandle)) !== false) {
             if ($file != "." && $file != "..") {
                 if (filemtime($dir . $file) < $today) {
                     if (is_dir($dir . $file)) {
                         del_dir($dir . $file);
                     } else {
                         @unlink($dir . $file);
                     }
                 }
             }
         }
         @closedir($dirhandle);
         $this->ajaxReturn('', buildFormToken(), 1);
     }
 }
Exemplo n.º 2
0
function ml_image_uploads_file($mid, $field = "imagefile", $flv = false)
{
    global $xoopsModuleConfig, $errors;
    if (empty($_FILES[$field])) {
        $errors[] = _MD_UPLOADS_ERROR_FAIL;
        return false;
    }
    $upfile =& $_FILES[$field];
    if (empty($upfile['size'])) {
        $errors[] = _MD_UPLOADS_ERROR_SIZE;
        return false;
    }
    //global $upload_types;
    //if (!in_array($upfile['type'], $upload_types)) return false;
    $fname = $upfile['name'];
    if (!preg_match('/\\.(' . $xoopsModuleConfig['upload_ext'] . ')$/i', $fname)) {
        $errors[] = _MD_UPLOADS_ERROR_EXT;
        return false;
    }
    $path = get_upload_path($mid);
    if (!preg_match('/^([a-z]:)?\\//i', $path)) {
        $path = XOOPS_UPLOAD_PATH . "/" . $path;
    }
    if (!is_dir(dirname($path))) {
        mkdir(dirname($path));
    }
    if (!is_dir($path)) {
        mkdir($path);
    }
    $temp = $upfile['tmp_name'];
    if ($flv && preg_match(_VIDEO_EXT, $fname, $d)) {
        $ext = $d[1];
        rename($temp, $temp . "." . $ext);
        $temp .= "." . $ext;
        // set original extention for converter
        $fname = preg_replace("/\\.{$ext}\$/", '.flv', $fname);
        $tofile = "{$path}/{$fname}";
        $base = dirname(__FILE__);
        $ret = convert_flv($temp, $tofile);
        unlink($temp);
        if (!$ret) {
            $errors[] = _MD_CONVERT_FAIL;
            return false;
        }
    } else {
        $tofile = "{$path}/{$fname}";
        if (!move_uploaded_file($temp, $tofile)) {
            $errors[] = _MD_UPLOADS_ERROR_FAIL;
            return false;
        }
    }
    return $fname;
}
Exemplo n.º 3
0
function ml_screenshot($mid)
{
    global $ml_shotopts;
    $path = get_upload_path($mid, _ML_SHOTNAME);
    if (!file_exists($path)) {
        global $xoopsDB;
        $res = $xoopsDB->query("SELECT url FROM " . $xoopsDB->prefix('medialinks_attach') . " WHERE midref={$mid} AND ltype='m' ORDER BY weight,linkid", 1);
        list($url) = $xoopsDB->fetchRow($res);
        if (preg_match('/^(\\w+:)\\//', $url)) {
            // get temporarily for screenshot
            $vfile = get_upload_path($mid, basename($url));
            if (!file_exists($vfile)) {
                // already get?
                if (!is_dir(dirname($vfile))) {
                    mkdir(dirname($vfile));
                }
                system("wget -q -O '{$vfile}' '{$url}'");
                $temp = $vfile;
            }
        } else {
            $vfile = get_upload_path($mid, $url);
        }
        if (file_exists($vfile)) {
            global $mlModuleConfig;
            // NOTE: this script refer from blocks
            $opts = $mlModuleConfig['shotopts'];
            $cmdpath = $mlModuleConfig['cmdpath'];
            if (!empty($cmdpath)) {
                putenv("PATH={$cmdpath}");
            }
            if (preg_match(_VIDEO_EXT, $vfile)) {
                system("ffmpeg -i \"{$vfile}\" {$opts} -vcodec mjpeg -vframes 1 -an -f rawvideo -y \"{$path}\"");
            } elseif (preg_match(_IMAGE_EXT, $vfile)) {
                system("convert \"{$vfile}\" -resize 320 \"{$path}\"");
            }
            if (filesize($path) == 0) {
                unlink($path);
            }
        }
    }
    if (!file_exists($path)) {
        $mydirname = basename(dirname(__FILE__));
        return XOOPS_URL . "/modules/{$mydirname}/images/nodata.png";
    }
    if (!empty($temp) && file_exists($temp)) {
        unlink($temp);
    }
    return get_upload_url($mid, _ML_SHOTNAME);
}
Exemplo n.º 4
0
function file_argument($media_type, $name, $default = null)
{
    $mime = check_media_type($media_type);
    // upload file
    if (isset($_FILES[$name])) {
        if ($_FILES[$name]['error'] == UPLOAD_ERR_OK) {
            $destination = get_upload_path($mime, $_FILES[$name]['name']);
            move_uploaded_file($_FILES[$name]['tmp_name'], $destination['path']);
            $media_url = $destination['url'];
        } else {
            throw new HttpError('file upload error: ' . $_FILES[$name]['error'], HttpError::BadRequest);
        }
    } else {
        if ($default !== null) {
            return $default;
        }
        throw new HttpError("argument {$name} missing", HttpError::BadRequest);
    }
    return $media_url;
}
Exemplo n.º 5
0
function get_upload_config($folder)
{
    $config = array();
    $config['upload_path'] = get_upload_path($folder);
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '1000';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';
    return $config;
}
Exemplo n.º 6
0
 function delAttach($id)
 {
     global $xoopsDB;
     if (!isset($this->attach[$id])) {
         return false;
     }
     $res = $xoopsDB->query("DELETE FROM " . ATTACH . " WHERE linkid=" . $id);
     if ($res) {
         $file = get_upload_path($this->getVar('mid'), $this->attach[$id]['url']);
         if ($file) {
             unlink($file);
         }
         unset($this->attach[$id]);
         $this->adirty[$id] = 0;
     }
     return $res;
 }
Exemplo n.º 7
0
 public function del()
 {
     if ($this->isAjax()) {
         if (C('TOKEN_ON') && !checkFormToken($_REQUEST)) {
             die('hack attemp.');
         }
         $id = intval($_REQUEST['id']);
         $ccmModel = D('MallZhekou');
         $zhekou = $ccmModel->info(array('logo'), $id);
         if ($ccmModel->_delete($id)) {
             $upload_path = get_upload_path();
             if (is_file(DOC_ROOT_PATH . $upload_path . $zhekou['logo'])) {
                 @unlink(DOC_ROOT_PATH . $upload_path . $zhekou['logo']);
             }
             $this->ajaxReturn('', buildFormToken(), 1);
         } else {
             $this->ajaxReturn('', '删除失败', 0);
         }
     }
 }
Exemplo n.º 8
0
 public function import()
 {
     if (!is_file(LIB_PATH . 'ORG/phpExcel/PHPExcel.php')) {
         $this->error('请先上传PHPExcel类库');
     }
     if ($this->isPost()) {
         if (C('TOKEN_ON') && !checkFormToken($_REQUEST, 'hash')) {
             die('hack attemp.');
         }
         $m_id = intval($_REQUEST['m_id']);
         $m_name = $_REQUEST['m_name'];
         $import_format = $_REQUEST['import_format'];
         $file = '';
         if ($_FILES['codes']['size'] > 0 && $_FILES['codes']['error'] == 0) {
             $upfile = array();
             $upfile = upload_one_file($_FILES['codes']);
             if ($upfile['error']) {
                 $this->error($upfile['error']);
             }
             $file = DOC_ROOT_PATH . get_upload_path() . $upfile['file_name'];
         } else {
             $this->error('Excel文件导入失败,请重试.');
         }
         if (!is_file($file)) {
             $this->error('Excel文件导入失败,请重试.');
         }
         $hanlder = "_import_coupons_" . $import_format . "_handler";
         $this->{$hanlder}($m_id, $m_name, $file);
         $this->assign('jumpUrl', '?g=' . GROUP_NAME . '&m=' . MODULE_NAME);
         $this->success('导入成功');
     }
     $this->assign('import_format_conf', $this->_import_format_conf);
     $this->assign('hash', buildFormToken('hash'));
     $this->assign('ur_href', '优惠券管理 &gt; 批量导入');
     $this->display();
 }
Exemplo n.º 9
0
 /**
  * uploadify2.14
  * 批量上传文件
  * 
  */
 public function upload()
 {
     if (!$_POST['sid']) {
         die('hack attempt.');
     }
     if (session_id() !== $_POST['sid']) {
         $nowtimestamp = time();
         $timestamp = $_POST['timestamp'];
         $sessionid = $_POST['sid'];
         $authcode = $_POST['authcode'];
         $authdecode = md5($timestamp . $sessionid . C('AUTH'));
         if ($nowtimestamp - $timestamp >= 60 * 10 || $authdecode !== $authcode) {
             die('hack attempt.');
         }
     } else {
         $this->_chkLogin();
     }
     if (!empty($_FILES)) {
         $tempFile = $_FILES['Filedata']['tmp_name'];
         $upload_path = DOC_ROOT_PATH . get_upload_path();
         $targetPath = $upload_path . 'temp/' . date('Ymd') . '/';
         if (!is_dir($targetPath)) {
             mk_dir($targetPath, 0755);
         }
         $new_file_name = $this->_new_name($_FILES['Filedata']['name']);
         if (empty($new_file_name)) {
             die('error');
         }
         $targetFile = str_replace('//', '/', $targetPath) . $new_file_name;
         move_uploaded_file($tempFile, iconv('utf-8', 'gbk', $targetFile));
         //echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
         echo str_replace(DOC_ROOT_PATH, '', $targetFile);
     }
 }
Exemplo n.º 10
0
 /**
  * 删除
  *
  */
 public function del()
 {
     if ($this->isAjax()) {
         if (C('TOKEN_ON') && !checkFormToken($_REQUEST)) {
             die('hack attemp.');
         }
         $position_id = intval($_REQUEST['id']);
         $apModel = D('AdPosition');
         if ($apModel->del($position_id)) {
             //删除模板
             if (is_file(HTML_PATH . 'Adv/' . $position_id . '.html')) {
                 @unlink(HTML_PATH . 'Adv/' . $position_id . '.html');
             }
             //删除所有相关的广告
             $adModel = D('Ad');
             $ads = $adModel->getAdsByPositionId($position_id);
             $upload_path = DOC_ROOT_PATH . get_upload_path();
             foreach ($ads as $a) {
                 $ad = $adModel->info($a['ad_id']);
                 if (is_file($upload_path . $ad['ad_code'])) {
                     @unlink($upload_path . $ad['ad_code']);
                 }
                 $adModel->del($a['ad_id']);
                 //更新缓存
                 $params = array('ad_id' => $a['ad_id']);
                 B('Adv', $params);
             }
             //更新缓存
             $params = array('pos_id' => $position_id);
             B('Adv', $params);
             $this->ajaxReturn('', buildFormToken(), 1);
         } else {
             $this->ajaxReturn('', '', 0);
         }
     }
 }
Exemplo n.º 11
0
 /**
  * 删除
  *
  */
 public function del()
 {
     if ($this->isAjax()) {
         if (C('TOKEN_ON') && !checkFormToken($_REQUEST)) {
             die('hack attemp.');
         }
         $ad_id = intval($_REQUEST['ad_id']);
         $adModel = D('Ad');
         $ad = $adModel->info($ad_id);
         if ($adModel->del($ad_id)) {
             $upload_path = DOC_ROOT_PATH . get_upload_path();
             if (is_file($upload_path . $ad['ad_code'])) {
                 @unlink($upload_path . $ad['ad_code']);
             }
             //更新缓存
             $params = array('ad_id' => $ad_id);
             B('Adv', $params);
             $this->ajaxReturn('', buildFormToken(), 1);
         } else {
             $this->ajaxReturn('', '', 0);
         }
     }
 }
Exemplo n.º 12
0
function contents_delete()
{
    global $xoopsDB, $xoopsModule;
    $dels = array();
    foreach ($_POST['dels'] as $v) {
        $dels[] = intval($v);
    }
    $delset = join(',', $dels);
    $res = $xoopsDB->query("DELETE FROM " . MAIN . " WHERE mid IN ({$delset})");
    if ($res) {
        $xoopsDB->query("DELETE FROM " . ATTACH . " WHERE midref IN ({$delset})");
        $xoopsDB->query("DELETE FROM " . RELAY . " WHERE midref IN ({$delset})");
        $xoopsDB->query("DELETE FROM " . $xoopsDB->prefix('xoopscomments') . " WHERE com_modid=" . $xoopsModule->getVar('mid') . " AND com_itemid IN  ({$delset})");
        foreach ($dels as $mid) {
            $dir = get_upload_path($mid);
            if (is_dir($dir)) {
                $dh = opendir($dir);
                while ($file = readdir($dh)) {
                    if ($file != '.' && $file != '..') {
                        unlink("{$dir}/{$file}");
                    }
                }
                closedir($dh);
                rmdir($dir);
            }
        }
    }
    return $res;
}