?? upload.cgi
字號:
#!d:/perl/bin/perl
#####################################
### 網友自薦Beta1.0
### 程式制作: CGI工作室
### 網址: bbss.126.com
### Email: bbss@kali.com.cn
### 請訪問本站獲得更多的CGI程序
### 禁止商業使用,商業定義--一切和有收入相關的網站(包括放置第二方盈利性廣告)
### 如有問題或BUG,請來信指正,本站將根據問題加以解決。
####################################
## 設置開始##
## Note: NO trailing slash
$rootdir=&mypath;
## Do you wish to allow all file types? yes/no (no capital letters)
$allowall = "no"; # 是否上傳所有的文件類型
## If the above = "no"; then which is the only extention to allow?
## Remember to have the LAST 4 characters i.e. .ext
$theext = ".jpg"; #如果上面設置不,可以上傳的文件類型
$thee = ".gif";
## The page you wish it to forward to when done:
## I.E. http://www.mydomainname.com/thankyou.html
#$donepage = "http://ads/"; #上傳成功后自動轉向地址
################################################
use vars qw($in);
use CGI qw(:cgi);
$in = new CGI;
$|++; # Flush Output
print "content-type:text/html\n\n";
my $fileName= $in->param("fn");
if ($fileName eq "") {
&error("文件名不能為空!");
exit 0;
}
else {
#檢查文件類型
if ($allowall eq "yes") {
$filetypeok = "yes";
}
else {
my $ext=lc(substr($fileName,length($fileName) - 4,4));
if ($ext eq $theext){
$filetypeok = "yes";
}
if ($ext eq $thee){
$filetypeok = "yes";
}
}
if ($filetypeok eq "yes") {
my $imagedir=$in->param("albumdir");
$imagedir="$rootdir/album/$imagedir";
#如果目錄不存在,就創建它。
if (!&exists($imagedir)) {
if(!mkdir ($imagedir, 0755)) {
&error("建立目錄失敗,請重試!");
exit 0;
}
}
my $fullfile= "$imagedir/$fileName";
#print $fullfile;
if (&exists($fullfile)) { #檢查同名文件是否存在
&error("“$fileName”已經存在,請改變文件名,然后再重新上傳!");
exit 0;
}
else { #創建上傳文件
my $file = $in->param("fdata");
my $file_size = 0;
open (OUTFILE, ">$fullfile");
binmode (OUTFILE); # For those O/S that care.
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
$file_size += $bytesread;
if (($file_size / 1000) > 60) {
close OUTFILE;
unlink ($fullfile);
&error("上傳文件失敗!你指定的文件大于我們限定的文件大小60Kb!");
exit 0;
}
}
close (OUTFILE);
#print "文件已上傳";
print "<script language='javascript'>window.close();</script>";
}
}
else {
&error("文件格式不正確,請上傳*.jpg文件或*.gif文件。");
exit 0;
}
}
sub mypath
{
$tempfilename=__FILE__;
if ($tempfilename=~/\\/) { $tempfilename=~ s/\\/\//g;}
if ($tempfilename) {
$mypath=substr($tempfilename,0,rindex($tempfilename,"/"));
}
else {
$mypath=substr($ENV{'PATH_TRANSLATED'},0,rindex($ENV{'PATH_TRANSLATED'},"\\"));
$mypath=~ s/\\/\//g;
}
}
sub exists {
# -----------------------------------------------------
# Checks to see if a file exists.
#
return -e shift;
}
sub error {
local ($errors) = @_;
$envtext_tab.= <<EOFXX;
<html>
<head>
<title>錯誤</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel=stylesheet type=text/css href='style.css'>
</head>
<body><br>
<table width="450" align="center" border="0" cellspacing="2" cellpadding="5">
<tr>
<td align=center> </td>
</tr>
<tr>
<td align=center><font color="red">$errors</font></td>
</tr>
<tr>
<td align="center" height="58">
<table border="1" cellspacing="0" cellpadding="2" bgcolor="#CCCCCC" bordercolorlight="#000000" bordercolordark="#FFFFFF" width="80" align="center">
<tr>
<td>
<div align="center" class="p9"><A href="javascript:history.back()"><font size=2>返 回</font></a></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
EOFXX
$envtext=$envtext_head.$envtext_tab.$envtext_var.$envtext2;
print $envtext;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -