Example #1
0
/**
* 创建目录,仅供系统内部调用
* @param string $dir 需要创建的目录
* @return bool 成功返回true,失败返回false
*/
function mkdir2($dir)
{
    if (!is_dir($dir)) {
        if (!mkdir2(dirname($dir))) {
            return false;
        }
        if (!mkdir($dir, 0777)) {
            return false;
        }
    }
    return true;
}
Example #2
0
function copy_dir($source, $destination)
{
    foreach (glob($source) as $file) {
        $newFile = (is_dir($destination) ? "{$destination}/" : '') . basename("{$file}");
        if (is_dir($file)) {
            mkdir2($newFile);
            copy_dir("{$file}/*", $newFile);
        } else {
            copy($file, $newFile);
        }
    }
}
 function execute($newfile = '', $mkdir = true)
 {
     $this->newFileName($newfile);
     if ($mkdir && !is_dir($this->updir)) {
         mkdir2($this->updir);
     }
     $newfile = $newfile ? trim(strip_tags($this->updir . '/' . $newfile)) : trim($this->updir . '/' . $this->fname[0] . '.' . $this->getStuffix());
     if (is_uploaded_file($_FILES[$this->handle]['tmp_name'])) {
         if (function_exists('move_uploaded_file') && @move_uploaded_file($_FILES[$this->handle]['tmp_name'], $newfile)) {
             @unlink($_FILES[$this->handle]['tmp_name']);
             return $newfile;
         } elseif (@copy($_FILES[$this->handle]['tmp_name'], $newfile)) {
             @unlink($_FILES[$this->handle]['tmp_name']);
             return $newfile;
         } else {
             $this->error .= "未上传成功可能原因:\n";
             if (!is_dir($this->updir)) {
                 $this->error .= $this->updir . "目录不存在\n";
             } elseif (!is_writeable($this->updir)) {
                 $this->error .= $this->updir . "目录没有写权限\n";
             }
             $this->showmessage();
             return false;
         }
     }
     return false;
 }
Example #4
0
function _loadimg($url)
{
    global $db, $proverbkey;
    $upYun = new UpYun("imgbuket", "tolecen", "11311451167llx");
    $fname = md5($url);
    $file = array();
    $oldfile = $db->fetch_first("select * from " . tname("file") . " where SUBSTRING(file_key,12,32)='" . $fname . "'");
    if ($oldfile['file_id'] > 0) {
        return array('id' => $oldfile['file_id'], 'farm' => 'farm1', 'bucket' => 'hbimg', 'key_path' => $oldfile['file_path'], 'key' => $oldfile['file_original'], 'type' => $oldfile['file_type'], 'width' => $oldfile['width'], 'height' => $oldfile['height']);
        exit;
    }
    $f = array('id' => 1, 'farm' => 'farm1', 'bucket' => 'hbimg', 'key_path' => '', 'key' => '', 'type' => 'image/jpeg', 'width' => '180', 'height' => '180');
    $r = proverb_getimagesize($url);
    $imgtype = array('jpg' => '0', 'gif' => '1', 'png' => '2', 'bmp' => '3');
    $stuffix = 'jpg';
    if (isset($r[0]) && $r[0] > 0) {
        $c = "abcdefghigklmnopqrstuvwxyz0123456789";
        $d = substr($c, rand(0, 20), 2) . '/' . substr($c, rand(0, 10), 2);
        $dir = ROOT_PATH . '/data/upload';
        mkdir2($dir);
        switch ($r['mime']) {
            case 'image/gif':
                $stuffix = 'gif';
                break;
            case 'image/png':
                $stuffix = 'png';
                break;
            case 'image/bmp':
                $stuffix = 'bmp';
                break;
            default:
                $stuffix = 'jpg';
                break;
        }
        file_put_contents($dir . '/' . $fname . '.' . $stuffix, bidcms_fsockopen($url, $url));
        $fileName = $fname . '.' . $stuffix;
        $filePath = str_replace(ROOT_PATH, "", $dir) . "/";
        $filekey = $proverbkey . $imgtype[$stuffix] . $fname . str_replace('/', '', $d);
        $fh = fopen($dir . "/" . $fileName, 'r');
        $upYun->writeFile("/" . $fileName, $fh);
        fclose($fh);
        if (is_file($dir . "/" . $fileName)) {
            @unlink($dir . "/" . $fileName);
        }
        $db->query("insert into " . tname("file") . "(`file_key`, `file_path`, `file_original`, `file_type`, `width`, `height`) values('" . $filekey . "','" . $filePath . "','" . $fileName . "','" . $r['mime'] . "','" . $r['0'] . "','" . $r[1] . "')");
        $file_id = $db->insert_id();
        if ($file_id) {
            $f = array('id' => $file_id, 'farm' => 'farm1', 'bucket' => 'hbimg', 'key_path' => $filePath, 'key' => $fileName, 'type' => $r['mime'], 'width' => $r[0], 'height' => $r[1]);
        }
    }
    return $f;
}
 function _autoInsertGroup($ids)
 {
     $container = $ids == -1 ? 'and id>0' : 'and id in (' . ($ids ? $ids : 0) . ')';
     $data = $this->tempsite->GetPage(array('isshow' => 0), $container);
     set_time_limit(0);
     foreach ($data as $k => $v) {
         $o = $v['oldprice'] > 0 ? $v['oldprice'] : 1;
         $data[$k]['discount'] = intval($v['nowprice'] * 100 / $v['oldprice']) / 10;
         $newtime = explode('+', $v['lasttime']);
         $startnewtime = explode('+', $v['starttime']);
         $data[$k]['grouptype'] = $grouptype;
         $data[$k]['cityname'] = $v['cityname'] ? $v['cityname'] : '其它';
         $data[$k]['cityid'] = $v['cityname'] ? Pinyin($v['cityname']) : 'qita';
         $lasttime = str_replace('日', '', str_replace('月', '-', str_replace('年', '-', trim($newtime[0]))));
         $lasttime = str_replace('秒', '', str_replace('分', ':', str_replace('时', ':', $lasttime)));
         $starttime = str_replace('日', '', str_replace('月', '-', str_replace('年', '-', trim($startnewtime[0]))));
         $starttime = str_replace('秒', '', str_replace('分', ':', str_replace('时', ':', $starttime)));
         $data[$k]['lasttime'] = strtotime($lasttime) > 0 ? strtotime($lasttime) : $lasttime;
         $data[$k]['starttime'] = strtotime($starttime) > 0 ? strtotime($starttime) : $starttime;
         $data[$k]['ispassed'] = $GLOBALS['setting']['site_allow_passed'] ? 1 : 0;
         if ($v['thumb']) {
             if ($GLOBALS['allowremote']) {
                 $thumb = $this->curl->get($v['thumb']);
                 if ($thumb) {
                     $file = explode('.', $v['thumb']);
                     $dir = 'data/upload/' . date('Y/m');
                     mkdir2(ROOT_PATH . '/' . $dir);
                     $stuff = str_replace('/', '', $file[count($file) - 1]);
                     if (!in_array(substr($stuff, 4), array('jpeg', 'png', 'jpg', 'gif'))) {
                         $stuff = 'jpg';
                     }
                     $file = md52(microtime()) . '.' . $stuff;
                     writefile(ROOT_PATH . '/' . $dir . '/' . $file, $thumb);
                     $data[$k]['thumb'] = $dir . '/' . $file;
                 } else {
                     $data[$k]['thumb'] = $v['thumb'];
                 }
             }
         }
     }
     foreach ($data as $k => $v) {
         $group = $this->group->GetOne('and subject="' . global_addslashes($v['subject']) . '" and siteid=' . $v['siteid']);
         if (!$group) {
             unset($v['id']);
             $this->group->InsertData($v);
         }
     }
     $this->tempsite->DeleteData('1 ' . $container);
     sleep(1);
 }
function mkdir2($dir)
{
    if (!is_dir(dirname($dir))) {
        mkdir2(dirname($dir));
    }
    return mkdir($dir);
}