首先上传2个文件:upload.php和upload_file.php文件内容如下:
upload.php
//-------------------------------
<?
require("global.php");
eval("echo upload_file();");
?>
//---------------------------------
upload_file.php
//----------------------------------
<?
require("global.php");
// Editable variables
$full_path = "c:/inetpub/wwwroot/bbs/upload/"; // full path to directory that you want to store the images in - directory must be CHMOD to 777
$filesize = "500000"; // this is the max file size that you'd like uploaded
// Initialize date and time variables
// These are inserted into the image URL to ensure unique names
$date = (date ("mdy")); // format looks like 121700 - Month, Day, Year
$time = (date ("His")); // format looks like 214521 - Hours, Minutes Seconds
// Check that the user has permission to post/upload
if ($bbuserid == 0)
{
eval("echo standarderror($bbtitle,"".gettemplate("error_nopermission")."");");
exit;
}
if ($bbusername == "" || (isset($bbusername))==0)
{
$getusername=$DB_site->query_first("SELECT username FROM user WHERE userid=$bbuserid");
$username=$getusername[username];
$bbusername = $username;
}
else
{
$username = $bbusername;
}
// Check file size
if ($userfile_size > $filesize) {
print "你的文件太大. <a href="javascript:history.back()">返回</a>再试.";
exit;
}
//Check file type
//if (!eregi(".jpg", ".gif", $userfile_name)) {
// print "文件类型错误,你只能上载.jpg或者.gif扩展名的图片文件。<br><a href="javascript:history.back()">返回</a>再试.";
// exit;
//}
// Copy the uploaded file to the proper directory
if (@copy ($userfile, "$full_path$username$date$time$userfile_name")) {
// Initialize BBCode tags for use in the Image URL - I know this is a cheap way to do this, but I was rushing :-)
$open_img_tag = "[img]";
$close_img_tag = "[/img]";
// Remove the temp file from the server
// unlink ($userfile);
// Begin User Code Presentation Page
print "<p>拷贝下面的代码到你的文章内容的适当位置。</p>";
print "<p><input type="text" size="80" value="$open_img_tag$bburl/upload/$username$date$time$userfile_name$close_img_tag"></p>";
print "<p><a href="javascript:self.close()">关闭窗口</font></a></p>";
print "<p><a href="$bburl/upload/$username$date$time$userfile_name" target="_blank">预览图象</font></a></p>";
}
?>
//------------------------
接下来把下面这个函数加入global.php中
//-----------------------------------------
function upload_file($title="",$username="",$password="") {
eval("$returnval = dovars("".gettemplate("upload")."");");
return $returnval;
}
//------------------------------------------
然后新建一个模板“upload”内容如下:
//-------------------------------------
<html>
<body>
<form enctype=multipart/form-data action=upload_file.php method=post>
<table width=50% cellpadding=3 cellspacing=3>
<tr>
<td><b>File To Upload:</b></td></tr>
<tr>
<td>
<input type=file name=userfile>
</td>
</tr>
</table>
<input type=hidden name=MAX_FILE_SIZE value=200000>
<input type=submit value=" Upload File ">
</form>
</body>
</html>
//----------------------------------------
接下来把下面这段程序分别加入你的newthread和newreply文件中
//------------------------------------------
<SCRIPT LANGUAGE="JavaScript">
<!--//
function Upload(path)
{
window.open(path,"upload","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,height=200,resizable=no,top=50,left=50");
}
//-->
</SCRIPT>
//--------------------------------------------
最后把下面这段程序加入newthread和newreply中
//-------------------------------
<a href="javascript:Upload('upload.php')">上载图片!</a><br>
//---------------------------------
图片上载hack添加完成!您可以用vB做你自己的贴图区拉!!
|