Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,030

HOME > ASP > ASP Forum > งง มากๆครับ เป็น error ที่ผมไม่เข้าใจเลยครับ เกี่ยวกับupload file ครับ



 

งง มากๆครับ เป็น error ที่ผมไม่เข้าใจเลยครับ เกี่ยวกับupload file ครับ

 



Topic : 002140

Guest




ผมเขียนโค้ดให้ insert ข้อมูลลง ตารางครับ แล้วก็จะมี upload ภาพลงfolder แล้วเก็บพาธเอาไว้ในฐานข้อมูลครับ

ผมเขียนโค้ดแบบนี้เอาไว้สองสามครั้งแล้ว แล้วก็มีของเพื่อนอีก มันคล้ายๆกันครับ
อันอื่นไม่มีปัญหา แต่อันนี้ โค้ดเหมือนๆกัน แค่ตัวแปร กับจำนวนฟิลล์ที่ลงตารางไม่เหมือนกันเท่านั้น แต่กลับ error ครับ
มันเป็นแบบนี้ครับ

Error Type:
Microsoft VBScript runtime (0x800A0005)
Invalid procedure call or argument
/alumnus/act_member.asp, line 23

แล้วก็ในโฟลเดอร์ที่ใช้เก็บรูปภาพ มันมีไฟล์รูปภาพนั้นอยู่ครับแต่เป็น o bytes

ผมลองให้อาจารย์ช่วยดู อาจารย์เองท่านก็งงเหมือนกันครับไม่ทราบเป็นอะไร
ผมจะเอาโค้ดมาให้ดูนะครับ
แต่มีอยู่ครั้งนึง ผมเพิ่ง format เครื่องใหม่ แล้วลอง run ดู มันทำได้ครั้งนึงครับ insert ข้อมูลลงแฟ้มข้อมูลทุกอย่าง
แต่พอลองอีกที ก็ไม่ได้แล้วอ่ะครับ
ผมคิดเอาเองนะครับว่าน่าจะเป็นที่โปรแกรมอะไรสักอย่างในเครื่อง แต่ script blocking ของ norton ผมเอาออกแล้วนะครับ
ขอความกรุณาผู้ทราบช่วยแนะนำด้วยครับ


'member.asp
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<!--#include file="connect.asp" -->
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
</head>

<body>
<form action="act_member.asp" method="post" enctype="multipart/form-data" name="form1">
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bordercolor="#FFFFFF" bgcolor="#33CCFF">
<td colspan="4"><font color="#666666">กรุณากรอกข้อมูลเพื่อตรวจสอบ</font></td>
</tr>
<tr>
<td width="16%">&nbsp;</td>
<td width="27%">รหัสนักศึกษา</td>
<td width="31%">&nbsp;</td>
<td width="26%">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>วัน/เดือน/ปีเกิด</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr bgcolor="#33CCFF">
<td height="20" colspan="4"><font color="#666666">กรุณากรอกข้อมูลเพื่อสมัครสมาชิก</font></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>ชื่อ</td>
<td><font size="2">
<input name = name type = text id="name" onKeyPress="return keyCheck(event, this)" size="30" maxlength="10">
</font><font color="#FF0000">*</font><font size="2"><br>
<br>
</font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>นามสกุล</td>
<td><font size="2">
<input name = surname type = text id="surname" onKeyPress="return keyCheck(event, this)" size="30" maxlength="10">
</font><font color="#FF0000">*</font><font size="2"><br>
<br>
</font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>ที่อยู่</td>
<td><font size="2">
<textarea name = address cols = 35 rows = 5 id="address"></textarea>
</font><font color="#FF0000">*</font><font size="2"> <br>
<br>
</font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="26">&nbsp;</td>
<td>จังหวัด</td>
<td><font size="2">
<%
Sql="Select * From province"
Set Rs1=conn.execute(sql)
%>
<select name="province" id="province" >
<option>เลือกจังหวัด</option>
<%while Not Rs1.EOF%>
<option value=<% =Rs1("province_id")%>>
<% =Rs1("province_name")%>
</option>
<%
Rs1.MoveNext
wend
rs1.close
%>
</select>
</font><font color="#FF0000">*</font><font size="2"><br>
<br>
</font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>เบอร์โทรศัพท์</td>
<td><font size="2">
<input name = phone type = text id="phone" onKeyPress="return keyCheck(event, this)" size="30" maxlength="30">
</font><font color="#FF0000">*</font><font size="2"><br>
<br>
</font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>เบอร์โทรศัพท์มือถือ</td>
<td><font size="2">
<input name = mobile type = text id="mobile" onKeyPress="return keyCheck(event, this)" size="30" maxlength="30">
</font><font size="2"><br>
<br>
</font></td>
<td><font color="#FF0000">&nbsp;</font></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>e-mail</td>
<td><font size="2">
<input name = email type = text id="email" onKeyPress="return keyCheck(event, this)" size="30" maxlength="50">
</font><font color="#FF0000">*</font><font size="2"><br>
<br>
</font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>รูปภาพ</td>
<td><font size="2">
<input name="pics" type="file" class="input_button3" id="pics" size="30">
<br>
</font></td>
<td><font color="#FF0000">&nbsp;</font></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>username</td>
<td><font size="2">
<input name = username type = text id="username" onKeyPress="return keyCheck(event, this)" size="30" maxlength="10">
</font><font color="#FF0000">*</font><font size="2"> <br>
<br>
</font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>password</td>
<td><font size="2">
<input name = password type = text id="password" onKeyPress="return keyCheck(event, this)" size="30" maxlength="30">
</font><font color="#FF0000">*</font><font size="2"><br>
<br>
</font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>กรุณาเลือกคำถาม</td>
<td><select name="question" text="กรุณาเลือกคำถาม">
<option selected>กรุณาเลือกคำถาม</option>
<option value="ชื่อสัตว์เลี้ยง">ชื่อสัตว์เลี้ยง</option>
<option value="สีที่ชอบ">สีที่ชอบ</option>
<option value="ชื่อคนรัก">ชื่อคนรัก</option>
<option value="ดารานักร้องที่ชื่นชอบ">ดารานักร้องที่ชื่นชอบ</option>
</select>
<font color="#FF0000">*</font><br>
<br>
</td>
<td><font color="#FF0000">*</font><font color="#FF0000">*</font>ในกรณีที่ลืมรหัสผ่าน</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>คำตอบ</td>
<td><font size="2">
<input name = answer type = text id="answer" onKeyPress="return keyCheck(event, this)" size="30" maxlength="30">
</font><font color="#FF0000">*</font><font size="2">&nbsp; </font></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input name="submit" type = submit value = "บันทึกข้อมูล" class="input_button3" >
&nbsp;&nbsp; <input name="reset" type = reset value = "ลบข้อมูล" class="input_button3"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table> <p>หมายเหตุ กรุณากรอกข้อมูลในช่องที่มี * ให้ครบถ้วน</p>
</form>
<p>&nbsp;</p>
</body>
</html>
'=================================================================


'act_member.asp
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<!--#include file="getuploaddata.asp"-->
<!--#include file="connect.asp"-->
<%
if uploaddata.Item("name").Item("value")="" or _
uploaddata.Item("surname").Item("value")="" or _
uploaddata.Item("address").Item("value")="" or _
uploaddata.Item("province").Item("value")="" or _
uploaddata.Item("phone").Item("value")="" or _
uploaddata.Item("email").Item("value")="" or _
uploaddata.Item("username").Item("value")="" or _
uploaddata.Item("password").Item("value")="" or _
uploaddata.Item("question").Item("value")="" or _
uploaddata.Item("answer").Item("value")="" then
response.write"<center><input type=button class=input_button3 value='กรอกข้อมูลไม่ครบ กลับไปกรอกข้อมูลใหม่ !!' onClick='history.go(-1)' ></center>"
else

filename = uploaddata.Item("pics").Item("filename")
pos_filebegin = InStrRev(filename,"\")
pos_fileend = Len(filename)
filename_new = Mid(filename,pos_filebegin+1,pos_fileend - pos_filebegin)
set fs = Server.CreateObject("Scripting.FileSystemObject")
set uploadfile = fs.CreateTextFile(Server.MapPath("file/"&filename_new))
uploadfile.write uploaddata.Item("pics").Item("value")
uploadfile.close

filename_new="file\"&filename_new
userid = session("username")
sql2 = "Select * from member where username='"&uploaddata.Item("username").Item("value")&"'"
Set rs1 = Server.CreateObject("ADODB.Recordset")

rs1.Open sql2, conn, 1,3,512
response.write(sql2)
if (Rs1.EOF) Then
sql="select * from member"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn, 1,3
if rs.recordcount <> 0 then
rs.addnew
rs("name")=uploaddata.Item("name").Item("value")
rs("surname")=uploaddata.Item("surname").Item("value")
rs("address")=uploaddata.Item("address").Item("value")
rs("province_id")=uploaddata.Item("province").Item("value")
rs("phone")=uploaddata.Item("phone").Item("value")
rs("mobile")=uploaddata.Item("mobile").Item("value")
rs("e_mail")=uploaddata.Item("email").Item("value")
rs("picture")=filename_new
rs("username")=uploaddata.Item("username").Item("value")
rs("password")=uploaddata.Item("password").Item("value")
rs("question")=uploaddata.Item("question").Item("value")
rs("answer")=uploaddata.Item("answer").Item("value")
rs.Update
With Response
.Write "<br><br><table align=center width=400 cellspacing=0 cellpadding=0 bgcolor=#ff6600><tr><td>"
.Write "<table align=center border=0 width='100%' cellpadding=1 cellspacing=1>"
.Write "<tr><td bgcolor=#ffffcc align=center>"
.Write "<b>Status : </b>&nbsp;&nbsp;<IMG SRC=picturs/icon_mini_register.gif >บันทึกข้อมูลเข้าสู่ระบบเรียบร้อยแล้ว "
.Write "</td></tr></table>"
.Write "</td></tr></table>"
End With
rs.close
else
end if
else
With Response
.Write "<br><br><table align=center width=400 cellspacing=0 cellpadding=0 bgcolor=#ff6600><tr><td>"
.Write "<table align=center border=0 width='100%' cellpadding=1 cellspacing=1>"
.Write "<tr><td bgcolor=#ffffcc align=center>"
.Write "<b>Status : </b>&nbsp;&nbsp;มีผู้ใช้ชื่อ user name นี้แล้ว"
.Write "</td></tr></table>"
.Write "</td></tr></table>"
End With
rs1.close
end if
end if
%>
<table width="200" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="right" bgcolor="#66CCFF">&nbsp;</td>
</tr>
<tr>
<td align="right" bgcolor="#66CCFF"><font size="2"> <font color="#FF0000"><a href="javascript:self.close();" ><font size="3">close
windows </font></a></font></font></td>
</tr>

</table>
'=========================================================


'connect.asp
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++
<%
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="&Server.MapPath("data.mdb")
%>
'=========================================================

'getuploaddata.asp
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<%
'-- ฟังค์ชั่นเปลี่ยน ข้อความ เป็น ข้อมูลไบนารี --
Function TextToBinary(text)
for i = 1 to Len(text)
character = mid(text,i,1)
TextToBinary = TextToBinary & ChrB(Asc(character))
next
End Function

'-- ฟังค์ชั่นเปลี่ยน ข้อมูลไบนารี กลับเป็น ข้อความ --
Function BinaryToText(Binary)
BinaryToText=""
for i =1 to LenB(Binary)
character = MidB(Binary,i,1)
BinaryToText = BinaryToText & Chr(AscB(character))
next
End Function

'-- กำหนดการใช้ Dictionary ทำให้เก็บข้อมูลได้มากคล้ายกับ Array --
set uploaddata = CreateObject("Scripting.Dictionary")

data = request.BinaryRead(request.TotalBytes)
posend = InstrB(1,data,TextToBinary(chr(13)))
header = MidB(data,1,posend-1)

endheader = header & TextToBinary("---")
pos_header = 1
pos_endheader = InstrB(1,data,endheader)

'-- การวนลูปเพื่อตัดข้อมูลที่ถูกส่งมาให้ครบทั้งหมด --
Do While pos_header <> pos_endheader

set sub_uploaddata = CreateObject("Scripting.Dictionary")

'--ตัดชื่อ (ชื่อตัวแปรของช่อง) ช่องกรอกข้อมูลงทุกรูปแบบ เช่น textbox radio combobox เป็นต้น --
pos_name = InstrB(pos_header,data,TextToBinary("name="))
pos_namebegin = pos_name + 6
pos_nameend = InstrB(pos_namebegin,data,TextToBinary(chr(34)))
name = BinaryToText(MidB(data,pos_namebegin,pos_nameend - pos_namebegin))

'-- ตรวจสอบว่าข้อมูลเป็นแบบปกติ หรือ เป็นช่องอัพโหลดไฟล์(ช่องอัพโหลดจะมีลักษณะขอ้มูลแตกต่างจากทั่ว ๆ ไป)
pos_file = InstrB(pos_nameend,data,TextToBinary("filename"))
enddata = InstrB(pos_nameend,data,header)
if (pos_file <> 0) and (pos_file < enddata) then

'---ข้อมูลเป็นชนิดไฟล์อัพโหลด ให้ทำการตัดชื่อไฟล์ออกมา (ชื่อไฟล์เป็น Value ของตัวอัพโหลดไฟล์)--
pos_filebegin = pos_file + 10
pos_fileend = InstrB(pos_filebegin,data,TextToBinary(chr(34)))
filename = BinaryToText(MidB(data,pos_filebegin,pos_fileend - pos_filebegin))

'--เก็บข้อมูลชื่อไฟลไว้ในออบเจ็ค Dictionary--
sub_uploaddata.add "filename", filename

pos_content = InstrB(pos_fileend,data,TextToBinary("Content-Type:"))
pos_contentbegin = pos_content + 14
pos_contentend = InstrB(pos_contentbegin,data,TextToBinary(chr(13)))
contenttype = BinaryToText(MidB(data,pos_contentbegin,pos_contentend - pos_contentbegin))

'--เก็บข้อมูล ชนิดของไฟล์ที่อัพโหลด (Content - Type) ในออบเจ็ค Dictionary--
sub_uploaddata.add "contenttype", contenttype

'--ตัดข้อมูลภายในไฟล์รูปภาพ--
pos_valuebegin = pos_contentend + 4
pos_valueend = InstrB(pos_valuebegin,data,header) - 2
value = BinaryToText(MidB(data,pos_valuebegin,pos_valueend - pos_valuebegin))

'--เก็บข้อมูลภายในไฟล์รูปภาพ ลงในออบเจ็ค Dictionary--
sub_uploaddata.add "value",value


else

'--ตัดข้อมูลภายในไฟล์ทั่วไป(ไม่ใช่รูปภาพ)--
pos_valuebegin = pos_nameend + 5
pos_valueend = InstrB(pos_valuebegin,data,header) - 2
value = BinaryToText(MidB(data,pos_valuebegin,pos_valueend - pos_valuebegin))

'--เก็บข้อมูลภายในไฟล์ทั่วไป ลงในออบเจ็ค Dictionary--
sub_uploaddata.add "value",value

end if


'-- เก็บข้อมูลทั้งหมดลงใน Dictionary ชื่อ uploaddata--
uploaddata.add name,sub_uploaddata

'--เปลี่ยนตำแหน่ง Header ไปยังข้อมูลถัดไป(ถ้าหากมี) โดยทำการวนลูปเช็คเงื่อนไข--
pos_header = InstrB(pos_header+LenB(header),data,header)
loop
%>
'================================================================


Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 6 ธ.ค. 2547 23:48:31 By : gototon View : 3097 Reply : 3
 

 

No. 1

Guest


ไม่มีใครมาโพสเลยอ่ะ ช่วยโพสนะอย่าโกรธกันนะ บับบายจ้าพรุ่งนี้เจอกัน






Date : 7 ธ.ค. 2547 17:13:59 By : ทิมเองจ้า
 


 

No. 2



โพสกระทู้ ( 94 )
บทความ ( 0 )



สถานะออฟไลน์


มันน่าจะเกิดจากการกำหนด permission ของเครื่องจะครับ ไม่ทราบว่าใช้ winxp ใช่หรือเปล่าครับถ้าใช้ลองไปดูที่นี่นะครับ
https://www.thaicreate.com/asp/forum/001876.html
Date : 13 ธ.ค. 2547 08:48:54 By : tuntigon
 

 

No. 3



โพสกระทู้ ( 96 )
บทความ ( 0 )



สถานะออฟไลน์


ผมทำตามนั้นทั้งหมดแล้วครับ
แต่แก้ไม่ได้เหมือนเดิมครับ
ลองเอาไปรันใน win me ก็จะเป็นอาการที่นิ่งไปเลยครับ
จนกระทั่งมัน time out ไปเลยครับ
Date : 13 ธ.ค. 2547 15:19:30 By : gototon
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : งง มากๆครับ เป็น error ที่ผมไม่เข้าใจเลยครับ เกี่ยวกับupload file ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่