isno
(小仙)
版主
  
好想谈恋爱
UID 78818
精华
1
积分 115504
帖子 3960
金钱 113946 喜悦币
威望 10
人脉 1548
阅读权限 100
注册 2006-8-22
状态 在线
|
[推荐阅读] php不断查询50万记录的数据库的网站如何做?
sablog里面的
// 获得文件扩展名
function getextension($filename) {
return substr(strrchr($filename, "."), 1);
}
// 上传附件函数
function acceptupload() {
global $DB, $db_prefix, $attachment, $tmark, $sortid, $aidtmp, $attachment_size, $attachment_name, $attachment_type, $options;
$attachment_name = strtolower($attachment_name);
$extension = getextension($attachment_name);
if (is_uploaded_file($attachment)) {
$fnamehash = md5(uniqid(microtime()));
// 判断上传目录的方式
switch($options['attachsave']) {
case 1: $attachsubdir = "/"; break;
case 2: $attachsubdir = "/cate_".$sortid."/"; break;
case 3: $attachsubdir = "/month_".date('Ym')."/"; break;
case 4: $attachsubdir = "/day_".date('Ymd')."/"; break;
case 5: $attachsubdir = "/ext_".$extension."/"; break;
}
// 取得附件目录的绝对路径
$attach_dir = "../".$options['attachments_dir'].$attachsubdir;
if(!is_dir($attach_dir)) {
mkdir($attach_dir, 0777);
fclose(fopen($attach_dir.'/index.htm', 'w'));
}
// 判断上传的类型
if (!in_array($extension, array('gif', 'jpg', 'jpeg', 'png'))) {
$path = $attach_dir.$fnamehash.".file";
$filepath =
$attachsubdir.$fnamehash.".file";
} else {
$path = $attach_dir.$fnamehash.".".$extension;
$filepath = $attachsubdir.$fnamehash.".".$extension;
}
// 如果一种函数上传失败,还可以用其他函数上传
if (function_exists("move_uploaded_file") AND @move_uploaded_file($attachment, $path)) {
@chmod ($path, 0666);
$attachment = $path;
} else if (@copy($attachment, $path)) {
@chmod ($path, 0666);
$attachment = $path;
} else if (@is_readable($attachment)) {
if ($fp = @fopen($attachment,'rb')) {
@flock($fp,2);
$filedata = @fread($fp,@filesize($attachment));
@fclose($fp);
}
if ($fp = @fopen($path, 'wb')) {
@flock($fp, 2);
@fwrite($fp, $filedata);
@fclose($fp);
@chmod ($path, 0666);
$attachment = $path;
} else {
// 都不能上传,我也没办法
sa_exit("上传附件发生意外错误!", "javascript:history.go(-1);");
}
}
$filesize=@filesize($attachment);
if ($filesize != $attachment_size) {
@unlink($attachment);
sa_exit("上传附件发生意外错误!", "javascript:history.go(-1);");
}
// 判断是否为图片格式
if ($extension == "gif" or $extension == "jpg" or $extension == "jpeg" or $extension == "png") {
if ($imginfo=@getimagesize($attachment)) {
if (!$imginfo[2]) {
@unlink($attachment);
sa_exit("上传的文件不是一个有效的GIF或者JPG文件!", "javascript:history.go(-1);");
} else {
$isimage = '1';
}
}
// 判断是否使用缩略图
if ($options['viewthumbs']) {
$size = explode("x", strtolower($options['thumbssize']));
if (($imginfo[0] > $size[0]) OR ($imginfo[1] > $size[1])) {
$attach_thumb = array(
'filepath' => $attachment,
'filename' => $fnamehash,
'extension' => $extension,
'attachsubdir' => $attachsubdir,
'thumbswidth' => $size[0],
'thumbsheight' => $size[1],
);
$thumb_data = generate_thumbnail($attach_thumb);
$attach_data['thumbwidth'] = $thumb_data['thumbwidth'];
$attach_data['thumbheight'] = $thumb_data['thumbheight'];
$attach_data['thumblocation'] = $attachsubdir.$thumb_data['thumblocation'];
}
}
}
// 把文件信息插入数据库
$DB->query("INSERT INTO ".$db_prefix."attachment (filename,filesize,filetype,filepath,addtime,counter,isimage,thumb_location,thumb_width,thumb_height) VALUES ('".addslashes($attachment_name)."', '".filesize($attachment)."', '".addslashes($attachment_type)."', '".addslashes($filepath)."', '".time()."', '0', '".$isimage."', '".$attach_data['thumblocation']."', '".$attach_data['thumbwidth']."','".$attach_data['thumbheight']."')");
$aidtmp = $DB->insert_id();
// 返回当前使用的id
}
}
|
|