十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
這個(gè)很簡(jiǎn)單的,不是什么問題。但是,重點(diǎn)是,你的小說是什么格式。咱們以最常見的txt格式為例來討論這個(gè)問題。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:主機(jī)域名、網(wǎng)站空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、黃巖網(wǎng)站維護(hù)、網(wǎng)站推廣。
1.數(shù)據(jù)庫(kù)里應(yīng)該設(shè)計(jì)“小說”表,存儲(chǔ)每一本“小說”的信息。而這個(gè)表里,需要有小說的id,名稱,作者等信息,而對(duì)應(yīng)的,還需要有一個(gè)小說存儲(chǔ)的地址信息,這個(gè)地址,就是小說在你服務(wù)端的地址,即你服務(wù)器硬盤上的存儲(chǔ)路徑。
2.客戶在讀小說時(shí),客戶端發(fā)送請(qǐng)求,服務(wù)端接收了客戶請(qǐng)求,通過請(qǐng)求數(shù)據(jù)庫(kù),找到每本“小說”的在服務(wù)器硬盤上的地址,然后可以選擇將字符串讀取出來傳送回客戶端,或者直接把地址告訴客戶端讓用戶進(jìn)行下載。
3.明白了這個(gè)設(shè)計(jì),更新也很簡(jiǎn)單。更新時(shí),首先需要將小說上傳至服務(wù)端硬盤;然后更新數(shù)據(jù)庫(kù),將小說的各種信息,包括存儲(chǔ)地址,維護(hù)進(jìn)數(shù)據(jù)庫(kù)(這一步可以專門做一個(gè)管理頁面進(jìn)行維護(hù)),這樣一本新的小說就更新完成了。
4.以上是大體的設(shè)計(jì)實(shí)現(xiàn)思路,你可以根據(jù)你的實(shí)際情況看下是否可行。
// 這是我寫的一個(gè)方法,里面只需要傳兩個(gè)參數(shù)就OK了,在任何地方調(diào)用此方法都可以文件上傳
/**
* 上傳文件
* @param file待上傳的文件
* @param storePath待存儲(chǔ)的路徑(該路徑還包括文件名)
*/
public void uploadFormFile(FormFile file,String storePath)throws Exception{
// 開始上傳
InputStream is =null;
OutputStream os =null;
try {
is = file.getInputStream();
os = new FileOutputStream(storePath);
int bytes = 0;
byte[] buffer = new byte[8192];
while ((bytes = is.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytes);
}
os.close();
is.close();
} catch (Exception e) {
throw e;
}
finally{
if(os!=null){
try{
os.close();
os=null;
}catch(Exception e1){
;
}
}
if(is!=null){
try{
is.close();
is=null;
}catch(Exception e1){
;
}
}
}
}
不能使用數(shù)據(jù)庫(kù),直接使用xml就行了。什么叫驗(yàn)證注冊(cè)功能不會(huì)?讀取XML,看看有沒有改用戶,如果有就去除該用戶,然后對(duì)比密碼就行了。建議一開始就解析XML,變成一個(gè)map數(shù)據(jù),key放用戶,密碼為value,把map放到application域中,然后驗(yàn)證的時(shí)候直接取出map就行了。
目測(cè)就兩功能:
1、注冊(cè)、登陸
2、上傳、列表顯示、下載。
不明白的是什么叫客戶端直接操作服務(wù)端的文件?把文件放到WEB-INF文件夾下面就可以保護(hù)了,客戶端不能直接訪問。
這是我用的asp的,圖片存在UpImages文件下,圖片文件存在數(shù)庫(kù)里,別外你自添加數(shù)據(jù)連接吧;
%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
title寫日記/title
% if session("user")="" then
response.write"非法操作"
response.end
end if
%
link href="Css.css" rel="stylesheet" type="text/css" /
style type="text/css"
!--
td { font-size: 12px; line-height: 18px; border-style: none; color: #333333}
body {
background-image: url(image/94d48012f93a637cf819b897.jpg);
}
.STYLE10 {font-size: 10px; font-family: "宋體"; }
.STYLE12 {font-size: 12px; font-family: "楷體_GB2312"; }
--
/style/head
!--#include file="Conn.asp"--
body
table width="800" border="0" align="center" cellspacing="0"
tr
th align="right" scope="col" span class="STYLE12"
script language="JavaScript" type="text/javascript"
var pp,mm,month;
mydate=new Date();
pp=mydate.getDay();
month=mydate.getMonth()+1;
switch(pp)
{case 0: mm="星期日";break;
case 1: mm="星期一";break;
case 2:mm="星期二";break;
case 3: mm="星期三";break;
case 4: mm="星期四" ;break;
case 5 : mm="星期五";break;
case 6 : mm="星期六";break;
}
document.write("今天是:"+mydate.getYear()+"年"+month+"月"+mydate.getDate()
+"日"+"nbsp"+mm+"nbsp");
/script
/span/th
/tr
tr
th height="40" scope="col"img src="image/top.gif" width="800" height="157" alt="書叢制作" //th
/tr
tr
td height="25" align="center" background="image/ph.gif"寫文章/td
/tr
/table
table width="800" border="0" align="center" cellpadding="0" cellspacing="0"
tr
td bgcolor="#CCFFFF"form action="write.asp?action=Addnew" method="post" enctype="multipart/form-data" name="form1" id="form1"
table width="800" border="0" cellspacing="0" cellpadding="0"
tr
td width="138" align="right"文章標(biāo)題:/td
td colspan="2"label
input name="title" type="text" id="title" /
/label/td
/tr
tr
td align="right"?/td
td width="236"label/label
label for="file"/label
input type="file" name="file" id="file" //td
td width="426"???? ?心情狀態(tài):
select name="select"
option value="一般" selected="selected"一般/option
option value="非常愉快"非常愉快/option
option value="愉快"愉快/option
option value="不好"不好/option
option value="失落"失落/option
/select/td
/tr
tr
td align="right"文章內(nèi)容:/td
td colspan="2"label
textarea name="content" cols="80" rows="20" id="content"/textarea
/label/td
/tr
tr
td align="right"操作:/td
td colspan="2"label
input type="submit" name="Submit" value="提交" /
/label/td
/tr
/table
/form
/td
/tr
/table
table width="800" border="0" align="center" cellspacing="0"
tr
th height="3" scope="col"hr size="1" //th
/tr
/table
table width="800" border="0" align="center" cellspacing="0"
tr
th align="center" scope="col"span class="STYLE10"Copyright 2009 ? All Rights Reserved.br /
版權(quán)所有: | 技術(shù)支持:a href="mailto:yaoyaovip@yahoo.com.cn"書叢/a | 渝ICP備000**0號(hào) /span/th
/tr
/table
%
if request("action") = "Addnew" then
newline = chrB(13) chrB(10) 'newline表示二進(jìn)制的回車符
filesize = Request.TotalBytes 'filesize是表單數(shù)據(jù)大小
filedata = Request.BinaryRead(filesize) 'filedata是表單的二進(jìn)制數(shù)據(jù)
divider = leftB(filedata,clng(instrb(filedata,newline))-1) 'divider是分割符
Set Rs = Server.CreateObject("ADODB.RecordSet")
Sql="Select * From word"
Rs.Open Sql,conn,3,3
Rs.addnew
k = 1
While instrb(k,filedata,divider) instrb((instrb(k,filedata,divider)+lenb(divider)),filedata,divider)
start = instrb(k,filedata,divider) + lenb(divider) +2
endsize = instrb((instrb(k,filedata,divider) + lenb(divider)),filedata,divider) - start - 2
content = midb(filedata,start,endsize) '取文件說明部分
start_name = instrb(content,toByte("name="""))
end_name = instrb(start_name + 6,content,toByte(""""))
nametag = midb(content,start_name+6,end_name-start_name-6) '取文件說明部分中name=""中的內(nèi)容,即表單元素的名稱
pos1_filename = instrb(end_name,content,toByte("filename="""))
'如果是文件框,則文件說明部分應(yīng)有filename="",那么pos1_filename不等于0
If pos1_filename = 0 Then '表單中不屬于文件上傳的數(shù)據(jù)處理
namevalue = toStr(midb(content,end_name+5,lenb(content)-end_name-4)) '取文件內(nèi)容
' 將文件說明部分的name=""中的內(nèi)容與表單元素的名稱進(jìn)行比較,把相應(yīng)的內(nèi)容加入數(shù)據(jù)庫(kù)
If(InStr(toStr(nametag),"file") 0)Then 'CenterID2'為表單控件的name屬性值,以下同
Rs("image") = namevalue
session("CenterID") = namevalue '用于上傳文件保存時(shí)的文件名中
End If
If(InStr(toStr(nametag),"title") 0)Then
Rs("title") = namevalue
if namevalue="" then
Response.Write "Scriptalert('請(qǐng)輸入標(biāo)題!')/Script"
response.end
end if
End If
If(InStr(toStr(nametag),"content") 0)Then
Rs("content") = namevalue
if namevalue="" then
Response.Write "Scriptalert('請(qǐng)輸入內(nèi)容!')/Script"
response.end
end if
End If
If(InStr(toStr(nametag),"select") 0)Then
Set Rs1 = Server.CreateObject("ADODB.RecordSet")
Sql="Select * From mun"
Rs1.Open Sql,conn,3,3
Rs1("mun")=namevalue
Rs1.update
Rs1.Close
Set Rs1=nothing
End If
Rs("wtime") = year(now)"-"month(now)"-"day(now)
'Response.Write (namevalue)
'Response.Write(" br")
else '處理文件上傳部分的數(shù)據(jù)
pos2_filename = instrb(pos1_filename+10,content,toByte(""""))
fullpath = midb(content,pos1_filename+10,pos2_filename-pos1_filename-10) '從文件說明部分中取出文件路徑
covername=GetFileName(toStr(fullpath))
If(fullpath "")Then '如果有上傳的文件,執(zhí)行以下代碼
dim bStart ' 取二進(jìn)制流文件部分開始位置
bStart = instrb(start,filedata,newlinenewline)+3
dim bEnd ' 取二進(jìn)制流文件部分結(jié)束位置
bEnd=inStrB(bStart+6,filedata,divider)-bStart-3
dim stm ' 定義一個(gè) adodb.stream 源對(duì)象 stm, 用以拷貝二進(jìn)制流文件部分至另一 adodb.stream fromStm
set stm=createObject("adodb.stream")
stm.type=1 ' 二進(jìn)制模式
stm.mode=3 ' 指定打開模式為讀寫
stm.open
stm.write filedata '寫入二進(jìn)制流內(nèi)容
dim fromStm '定義 adodb.stream 對(duì)象 fromStm, 以保存文件
set fromStm=createOBject("adodb.stream")
with fromStm
.type=1
.mode=3
.open
stm.position = bStart ' 指定 stm 對(duì)象的起始位置, 以變量 bStart 的值為起始位置
stm.copyTo fromStm, bEnd ' 拷貝 stm 二進(jìn)制流至 fromStm 對(duì)象, 長(zhǎng)度為 bEnd 變量的長(zhǎng)度
.saveTofile server.MapPath (covername),2' 保存文件, 如果存在相同名稱, 則覆蓋
.close
end with
set fromStm = nothing
stm.close
set stm = nothing
Rs("image") =covername '將文件的相對(duì)路徑寫入數(shù)據(jù)庫(kù)中
end if
end if
k = instrb((instrb(k,filedata,divider)+lenb(divider)),filedata,divider)
Wend
Rs.update
Rs.close
set Rs = nothing
response.Redirect"mylife.asp"
end if
function toStr(Byt) '將二進(jìn)制轉(zhuǎn)換為字符串
toStr=""
for i=1 to lenb(byt)
blow = midb(byt,i,1)
if ascb(blow)127 then
toStr = toStrchr(ascw(midb(byt,i+1,1)blow)) '
i = i+1
else
toStr = toStrchr(ascb(blow))
end if
Next
End function
Function toByte(Str) '將字符串轉(zhuǎn)換為二進(jìn)制
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode 0 Then iCode = iCode + 65535
If iCode255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte chrB("H"iLow) chrB("H"iHigh)
Else
toByte = toByte chrB(AscB(c))
End If
Next
End function
Function GetFileName(imagespath)'將路徑轉(zhuǎn)換為時(shí)間,并使上傳的文件不重名
If imagespath "" Then
rname=right(toStr(fullpath),len(toStr(fullpath))-InStrRev(toStr(fullpath),".")+1)'獲得后綴名
GetFileName = "UpImages/" year(now)month(now)day(now)hour(now)minute(now)second(now)rname
Else
GetFileName =""
End If
End Function
%
/body
/html
亂碼就是編碼格式的問題,處理字符串的時(shí)候加上編碼格式相關(guān)的轉(zhuǎn)換就ok了。