function thumb($url = '', $source = '', $name = '', $type = -1, $width = 0, $height = 0) { //如何生成不成功,则返回原url global $cms_abs, $cmsurl, $ftp_url, $atm_smallsite; if (!$url || !$source || !$name || !$width || !$height) { return $url; } include_once M_ROOT . "./include/upload.cls.php"; if ($ftp_url && preg_match(u_regcode($ftp_url), $url)) { //ftp上的文件 include_once M_ROOT . "./include/http.cls.php"; include_once M_ROOT . "./include/ftp.fun.php"; //下载原图 $tempfile = M_ROOT . './dynamic/imcache/' . basename($url); mmkdir($tempfile, 0, 1); $m_http = new http(); $m_http->savetofile($url, $tempfile); unset($m_http); //生成缩略图 $m_upload = new cls_upload(); $m_upload->image_resize($tempfile, $width, $height, $tempfile . '.s.jpg'); @unlink($tempfile); unset($m_upload); //上传缩略图 $ftpfile = preg_replace(u_regcode($ftp_url), '', $url) . 's/' . $width . '_' . $height . '.jpg'; //根据url得到缩略上传到的位置 $tempfile .= '.s.jpg'; if (ftp_upload($tempfile, $ftpfile)) { $this->refresh_record($source, $name, $type, $width, $height); //将缩略图规格写入数据库 return $url . 's/' . $width . '_' . $height . '.jpg'; } else { return $url; } @unlink($tempfile); } else { //本地服务器上的文件 $m_upload = new cls_upload(); $localfile = local_atm($url); $m_upload->image_resize($localfile, $width, $height, $localfile . 's/' . $width . '_' . $height . '.jpg'); unset($m_upload); return $url . 's/' . $width . '_' . $height . '.jpg'; } }
function remote_upload($remotefile, $rpid, $jumpfile = '*') { //jumpfile为允许的跳转文件格式 //返回数组 global $rprojects, $curuser, $memberid, $dir_userfile, $db, $tblprefix, $timestamp, $ftp_enabled; $result = array('remote' => $remotefile); if (!$this->capacity) { return $result; } if (empty($rpid) || empty($rprojects[$rpid]['rmfiles'])) { return $result; } if (islocal($remotefile, 1)) { return $result; } if (!empty($rprojects[$rpid]['excludes'])) { foreach ($rprojects[$rpid]['excludes'] as $k) { if (in_str($k, $remotefile)) { return $result; } } } $rmfiles = $rprojects[$rpid]['rmfiles']; $extension = strtolower(mextension($remotefile)); if (in_array($extension, array_keys($rmfiles))) { $rmfile = $rmfiles[$extension]; } else { return $result; } $uploadfile = array(); $uploadfile['mid'] = $curuser->info['mid']; $uploadfile['mname'] = $curuser->info['mname']; $file_saved = false; $uploadfile['filename'] = preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\\.|\$)/i", "_\\1\\2", date('dHis') . substr(md5($remotefile . microtime()), 5, 10) . random(4, 1) . '.' . $rmfile['extname']); $uploadpath = $this->upload_path($rmfile['ftype']); $uploadfile['url'] = $uploadpath . $uploadfile['filename']; $target = M_ROOT . $uploadpath . $uploadfile['filename']; @chmod($target, 0644); $m_http = new http(); if ($rprojects[$rpid]['timeout']) { $m_http->timeout = $rprojects[$rpid]['timeout']; } $file_saved = $m_http->savetofile($remotefile, $target, $rmfile['maxsize']); unset($m_http); if (!$file_saved) { @unlink($target); return $result; } if (filesize($target) < $rmfile['minisize'] * 1024) { @unlink($target); return $result; } $uploadfile['size'] = filesize($target); if (in_array($rmfile['extname'], array('jpg', 'jpeg', 'gif', 'png', 'swf', 'bmp'))) { //图片或是flash if (!($infos = @getimagesize($target))) { @unlink($target); return $result; } if (in_array($rmfile['extname'], array('jpg', 'jpeg', 'gif', 'png', 'bmp'))) { if ($this->image_watermark($target)) { $uploadfile['size'] = filesize($target); } $uploadfile['width'] = $infos[0]; $uploadfile['height'] = $infos[1]; } } if ($ftp_enabled) { include_once M_ROOT . "./include/ftp.fun.php"; ftp_upload($target, $uploadfile['url']); } $this->upload_size += ceil($uploadfile['size'] / 1024); if ($this->capacity != -1) { $this->capacity -= ceil($uploadfile['size'] / 1024); $this->capacity = max(0, $this->capacity); } $db->query("INSERT INTO {$tblprefix}userfiles SET\n\t\t\t\t\tfilename='{$uploadfile['filename']}',\n\t\t\t\t\turl='{$uploadfile['url']}',\n\t\t\t\t\ttype='{$rmfile['ftype']}',\n\t\t\t\t\tcreatedate='{$timestamp}',\n\t\t\t\t\tmid='{$uploadfile['mid']}',\n\t\t\t\t\tmname='{$uploadfile['mname']}',\n\t\t\t\t\tsize='{$uploadfile['size']}'\n\t\t\t\t\t"); if ($ufid = $db->insert_id()) { $this->ufids[] = $ufid; } $result['remote'] = $uploadfile['url']; $result['size'] = $uploadfile['size']; if (isset($uploadfile['width']) && isset($uploadfile['height'])) { $result['width'] = $uploadfile['width']; $result['height'] = $uploadfile['height']; } unset($uploadfile); return $result; }