⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadfile.ibas

📁 用iBASIC语言编写的HTTP服务器源代码例子。
💻 IBAS
字号:
' Write iBas code here!
include "word.ibas"
include "const.ibas"

register "/uploadfile"

function trackblock(fid, bound$, name$, id$)
	dim isok,rs,rett,file1$
	
	isok=0
	rs= ado_open_record("SELECT * FROM 文件列表")
	if ado_add_begin(rs)<=0 then goto exitt
	
	rett= ptr_extract_block( fid, bound$+HTTP_CR$, bound$+HTTP_CR$)
	print "返回1: ";rett
	
	if rett>0 then
		ptr_sub_head( rett, HTTP_CR$)
		ptr_sub_tail( rett, HTTP_CR$)
		if ptr_move_to( rett, HTTP_CR$+HTTP_CR$)>0 then file1$= ptr_write_string$(rett)
	else
		goto exitt
	end if
	'
	rett= ptr_extract_block( fid, bound$, bound$)
	print "返回2: ";rett
	'
	if rett>0 then
		dim newptr,tmp$,in0,in1,file2$
		newptr= ptr_extract_block( rett, "filename=", HTTP_CR$)
		if newptr<=0 then goto exitt
		tmp$= ptr_write_string$(newptr)
	
		in0= revfind( tmp$, ".")
		in1= revfind( tmp$, chr$(34))
		file2$="./upload/"+rand()+ mid$(tmp$, in0, in1-in0)	
		ptr_sub_head( rett, HTTP_CR$)
		ptr_sub_tail( rett, HTTP_CR$)
		if ptr_move_to( rett, HTTP_CR$+HTTP_CR$)>0 then
			print "Save file ", file2$,"begin...!"
			if ptr_write_file( rett, file2$)<=0 then goto exitt
			print "Save file ", file2$,"ok !"
		else
			goto exitt
		end if
	else
		goto exitt
	end if
	
	ado_add_string( rs, "文件名称", file1$)
	ado_add_string( rs, "文件完整目录", file2$)
	ado_add_string( rs, "文件编码", id$+rand())
	ado_add_string( rs, "用户名", name$)
	dim date$
	date$= get_time$()
	ado_add_date( rs, "上载时间", date$)
	
	if ado_update(rs)>0 then isok=1
	
	exitt:
	if isok>0 then
		{"发送成功!"}
		trackblock=1
	else
		{"发送失败"}
		trackblock=0
	end if
end function 


' main program
srand()

{"<html><body>"}

dim ref$,name$,id$,rsss

ref$= http_get_value$("Referer")
name$= findaword$(ref$, "name=","&")
id$=findaword$(ref$,"id=","&")

rsss=ado_open_record("select * from 用户登记表 where 用户名='"+ name$+"' AND 用户标识码='"+id$ +"' AND ip='"+net_get_ip$()+"'")

if ado_is_eof(rsss) then
	{"请先登录"}
	goto exit0
end if

dim fid,bound$,startx
fid=http_get_post(2048000)
if fid>0 then
	bound$=http_get_value$("Content-Type")
	startx= instr(bound$,"dary=",1)
	if startx>0 then bound$= mid$(bound$, startx+5, -1)

	print "trackblock() start...."
	if trackblock(fid, "--"+bound$,name$, id$)>0 then
		{"<hr><a href=list?name="+ name$+"&id="+id$+">返回</a>"}
	else
		{"<hr><a href=list?name="+ name$+"&id="+id$+">返回</a>"}
	end if
else
	print "too big file!"
	{"抱歉,接收错误!服务器只接受1M以下大小的文件。请重新发送..."}
end if


exit0:
{"</body></html>"}
http_send_flush()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -