【php开源代码栏目提醒】:本文主要为网学会员提供attachment.php,希望对需要attachment.php网友有所帮助,学习一下!
<?php
if(!defined('ROOT') || !isset($php_self) || !preg_match("/[\/\\\\]admincp\.php$/", $php_self)) {
exit('Access Denied');
}
//鏉冮檺妫鏌?
per
mission();
// 鍔犺浇闄勪欢鐩稿叧鍑芥暟
require_once(ROOT.'include/func_attachment.php');
//娣诲姞闄勪欢鍒版寚瀹氭枃绔?
if($action == 'addattachtoarticle') {
$articleid = intval($articleid);
$article = $DB->fetch_one_array("SELECT title,attachments,visible FROM {$db_prefix}articles WHERE articleid='$articleid'");
if(!$article) {
message('鏂囩珷涓嶅瓨鍦?, './');
}
// 淇敼闄勪欢
$oldattach = array();
if ($article['attachments']){
$oldattach = unserialize(stripslashes_array($article['attachments']));
}
require_once('uploadfiles.php');
if ($attachs){
$attachs=unserialize(stripslashes_array($attachs));
foreach ($attachs as $key => $value){
$oldattach[$key] = $value;
}
}
if ($oldattach){
$oldattach = addslashes(serialize($oldattach));
} else {
$oldattach = '';
}
if($attachmentids){
$DB->unbuffered_query("UPDATE {$db_prefix}attachments SET articleid='$articleid' WHERE attachmentid IN($attachmentids)");
}
// 淇敼闄勪欢缁撴潫
$DB->unbuffered_query("UPDATE {$db_prefix}articles SET attachments='$oldattach' WHERE articleid='$articleid'");
$DB->unbuffered_query("UPDATE {$db_prefix}statistics SET attachment_count=attachment_count+".$attachment_count);
redirect('鎴愬姛涓婁紶浜?.$attachment_count.'涓檮浠跺埌銆?.$article['title'].'銆?, 'admincp.php?go=attachment&action=list&articleid='.$articleid,'10');
}
//鎵归噺鍒犻櫎闄勪欢
if($action == 'delattachments') {
if ($attachmentids = implode_ids($_POST['attachment'])) {
$nokeep = array();
$query = $DB->query("SELECT attachmentid,filepath,thumb_filepath FROM {$db_prefix}attachments WHERE attachmentid IN ($attachmentids)");
while($attach = $DB->fetch_array($query)) {
$nokeep[$attach['attachmentid']] = $attach;
}
removeattachment($nokeep);
$articleid = intval($_POST['articleid']);
redirect('鎴愬姛鍒犻櫎鎵閫夐檮浠?濡傛灉鍒犻櫎鏁伴噺寰堝.寤鸿鎵ц涓娆¢檮浠朵慨澶嶆搷浣?鏇存柊鏂囩珷涓殑闄勪欢淇℃伅浠ユ彁楂樿闂熷害.', 'admincp.php?go=attachment&action=list&articleid='.$articleid,'10');
} else {
redirect('鏈夋嫨浠讳綍闄勪欢');
}
}
//闄勪欢淇
if($action == 'dorepair') {
$query = $DB->query("SELECT attachmentid,filepath FROM {$db_prefix}attachments");
while ($attach = $DB->fetch_array($query)) {
if(!file_exists('../'.$base['attachments_dir'].'/'.$attach['filepath'])){
$DB->unbuffered_query("DELETE FROM {$db_prefix}attachments WHERE attachmentid='".$attach['attachmentid']."'");
}
}
unset($attach,$query);
$count = 0;
$query = $DB->query("SELECT articleid,attachments FROM {$db_prefix}articles WHERE attachments <> ''");
while ($aids = $DB->fetch_array($query)) {
$attachs = unserialize(stripslashes_array($aids['attachments']));
if (is_array($attachs)) {
$update=0;
foreach ($attachs as $key=>$attach) {
if($attach['filepath'] && file_exists('../'.$base['attachments_dir'].'/'.$attach['filepath'])){
$check = $DB->fetch_one_array("SELECT attachmentid FROM {$db_prefix}attachments WHERE attachmentid='".$attach['attachmentid']."'");
if (!$check) {
$count++;
$attach['filename'] = addslashes($attach['filename']);
$DB->query("INSERT INTO {$db_prefix}attachments (filename, filesize, filetype, filepath, dateline, downloads, isimage, thumb_filepath, thumb_width, thumb_height) VALUES ('".addslashes($attach['filename'])."', '".addslashes($attach['filesize'])."', '".addslashes($attach['filetype'])."', '".addslashes($attach['filepath'])."', '".addslashes($attach['dateline'])."', '".addslashes($attach['downloads'])."', '".addslashes($attach['isimage'])."', '".addslashes($attach['thumb_filepath'])."', '".addslashes($attach['thumb_width'])."', '".addslashes($attach['thumb_height'])."')");
}
} else{
$count++;
$check = $DB->fetch_one_array("SELECT attachmentid FROM {$db_prefix}attachments WHERE attachmentid='".$attach['attachmentid']."'");
if($check){
$DB->unbuffered_query("DELETE FROM {$db_prefix}attachments WHERE attachmentid='"