10/10/2018, 10:10
Upload file trong Localhost bằng ASP. Sao lại củ chuối thế. Cái lổi này mong được gúp
Tui có một cái trang web viet bằng ASP với Database Access nhưng khi upload file hình ảnh *.jpeg, *.gift. *.HTML, WMA,WMV... lên domain hosting thì được, nhưng khi chạy trong localhost thì nó báo lổi không Up được. Vậy muốn upload trong Localhost thì phải sửa lại cái gì mới được.! Mong các bác chỉ giáo cho.
Báo là file lib_upload.asp err line 17.
------------------------------------
Đây là nội dung file .
------------------------------------
<%
dim g_intUploadType
g_intUploadType=0
%>
<%
'uploadFile
sub uploadFile(strFileName, strFileLocation, blnUploadType)
'On Error Resume Next
dim objFileSystem
dim objUpload
if blnUploadType=0 then
set objFileSystem = CreateObject("Scripting.FileSystemObject")
if not(objFileSystem.FolderExists(strFileLocation)) then objFileSystem.CreateFolder(strFileLocation)
set objUpload= Server.CreateObject("Persits.Upload.1")
objUpload.SetMaxSize 5000000,true
objUpload.Save(strFileLocation)
strFileName=objUpload.Files("strFileName").Path
elseif blnUploadType=1 then
set objFileSystem = CreateObject("Scripting.FileSystemObject")
if not(objFileSystem.FolderExists(strFileLocation)) then objFileSystem.CreateFolder(strFileLocation)
Set objUpload= Server.CreateObject("SoftArtisans.FileUp")
objUpload.Path=strFileLocation
objUpload.Form("strFileName").Save
strFileName=objUpload.Form("strFileName").ServerNa me
end if
if (Err.number<>0) then
Response.Write Err.description
end if
end sub %>
<%'delFolder
sub delFolder(FolderPath)
dim objFileSystem, strFolderPath
set objFileSystem = CreateObject("Scripting.FileSystemObject")
if FolderPath <> "" then
strFolderPath=server.MapPath(FolderPath)
if objFileSystem.FolderExists(strFolderPath) then objFileSystem.DeleteFolder(strFolderPath)
end if
end sub
%>
<% 'del file
function delFile(strSource)
dim objFileSystem
dim fsFile
on error resume next
set objFileSystem=CreateObject("Scripting.FileSystemOb ject")
set fsFile=objFileSystem.GetFile(strSource)
fsFile.Delete true
end function
%>
<% sub uploadFile1(file1, file2, file3, file4, file5, file6, file7, file8, file9, file10, strFileLocation)
On Error Resume Next
dim fs
dim objUpload
if g_intUploadType=0 then
set fs = CreateObject("Scripting.FileSystemObject")
if not(fs.FolderExists(strFileLocation)) then fs.CreateFolder(strFileLocation)
set objUpload= Server.CreateObject("Persits.Upload.1")
objUpload.SetMaxSize 5000000,true
objUpload.Save(strFileLocation)
file1=objUpload.Files("file1").Path
file2=objUpload.Files("file2").Path
file3=objUpload.Files("file3").Path
file4=objUpload.Files("file4").Path
file5=objUpload.Files("file5").Path
file6=objUpload.Files("file6").Path
file7=objUpload.Files("file7").Path
file8=objUpload.Files("file8").Path
file9=objUpload.Files("file9").Path
file10=objUpload.Files("file10").Path
elseif g_intUploadType=1 then
set fs = CreateObject("Scripting.FileSystemObject")
if not(fs.FolderExists(strFileLocation)) then fs.CreateFolder(strFileLocation)
Set objUpload= Server.CreateObject("SoftArtisans.FileUp")
objUpload.Path=strFileLocation
objUpload.Form("file1").Save
objUpload.Form("file2").Save
objUpload.Form("file3").Save
objUpload.Form("file4").Save
objUpload.Form("file5").Save
objUpload.Form("file6").Save
objUpload.Form("file7").Save
objUpload.Form("file8").Save
objUpload.Form("file9").Save
objUpload.Form("file10").Save
file1=objUpload.Form("file1").ServerName
file2=objUpload.Form("file2").ServerName
file3=objUpload.Form("file3").ServerName
file4=objUpload.Form("file4").ServerName
file5=objUpload.Form("file5").ServerName
file6=objUpload.Form("file6").ServerName
file7=objUpload.Form("file7").ServerName
file8=objUpload.Form("file8").ServerName
file9=objUpload.Form("file9").ServerName
file10=objUpload.Form("file10").ServerName
end if
if (Err.number<>0) then
Response.Write Err.description
end if
end sub %>
-----------------------------------------------------------------------
Và file produc_upload_images.asp
Sau đây là nội dung file
-----------------------------------------------------------------------
<!--#include file="../include/lib_init.asp"-->
<!--#include file="../include/lib_utilities.asp"-->
<!--#include file="../include/lib_manager.asp"-->
<!--#include file="../include/lib_database.asp"-->
<!--#include file="../include/lib_grid.asp"-->
<!--#include file="../include/lib_form.asp"-->
<!--#include file="../include/lib_upload.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Upload hinh anh</title>
<link rel="stylesheet" type="text/css" href="style_manager.css">
<link rel="stylesheet" type="text/css" href="style_grid.css">
</head>
<script language="javascript" src="../ClientScripts/Utilities.js"></script>
<script language="javascript" src="../ClientScripts/Utilities_manager.js"></script>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<% g_intSubHighlight=100 %>
<!--#include file="header_product.asp"-->
<% 'main content
dim PRO_ID, PRO_IMAGE1, PRO_IMAGE2, PRO_IMAGE3, PRO_IMAGE4, PRO_IMAGE5
dim intImage, strCatImage, strFileName, strFileNameTemp, strSql
dim strAction, strName, strCaption, strTitleForm
dim strLinkBack, strLinkSave, strLinkDelete
dim intPageStatus
dim strGetImage, strTmpCatImage
PRO_ID=getNumberValid(Request("PRO_ID"),0)
if (PRO_ID=0) then Response.Redirect "default.asp"
intImage=getNumberValid(Request("image_id"),0)
strAction="product_upload_image.asp?image_id=" & intImage & "&pro_id=" & PRO_ID
strTitleForm="Upload hinh anh"
strLinkBack="product_upload_list.asp?pro_id=" & PRO_ID
strLinkSave="product_upload_list.asp?pro_id=" & PRO_ID
if intImage<>6 then
strSql=" SELECT PRO_IMAGE" & intImage & " FROM SHOPASP_PRODUCT WHERE PRO_ID=" & PRO_ID
strFileName=getSingleValue(strSql)
strFileNameTemp=strFileName
end if
if Request.ServerVariables("request_method")="POST" then
call uploadFileLocal(g_intUploadType)
call saveDatabase()
else
Select case intImage
Case 1 strTmpCatImage="Hình minh họa nhỏ"
Case 2 strTmpCatImage="Hình minh họa lớn"
Case 3 strTmpCatImage="Hình ảnh chi tiết"
Case 4 strTmpCatImage="Hình ảnh 4"
Case 5 strTmpCatImage="Hình ảnh 5"
Case 6 strTmpCatImage="File kèm theo file HTML"
End Select
call showProduct(PRO_ID)
call showForm()
end if
%>
<!--#include file="footer.asp"-->
<% 'showForm()
sub showForm() %>
<table border="0" cellspacing="1" cellpadding="3" class="tdGridTable" align="center">
<form action="<%=strAction%>" ENCTYPE="MULTIPART/FORM-DATA" method="POST" name="frmUpload" id="frmUpload">
<tr>
<td class="tdGridTitle" colspan="2">
<%=strTitleForm%>
<% if not(IsNaS(strLinkBack)) then %> <a href="<%=strLinkBack%>"><span class="linkAdd">Back</span></a> <% end if %>
</td>
</tr>
<tr class="tdGridRow">
<td><b><%call showStringUnicode(strTmpCatImage)%>:</b></td>
<td><input type="file" name="strFileName" id="strFileName" size="50" onchange="InsertImage(this)"></td>
</tr>
<% dim path: path=getPathProduct(PRO_ID)%>
<% call showFieldInput (strTmpCatImage & " (local):", "IMAGE_LOCAL", "image", "", "", 0, 0 , 0, false, false, false) %>
<% call showFieldInput (strTmpCatImage & ":", "IMAGE_SERVER", "image", "", path & strFileName, 0, 0 , 0, false, false, false) %>
<tr>
<td class="tdGridTitle" colspan="2">
<% call showSaveResetBackButton()%>
</td>
</tr>
</form>
</table>
<% end sub %>
<% 'uploadFileLocal
sub uploadFileLocal(intUploadType)
dim strFilePath, strFileLocation
strFilePath=getPathProduct(PRO_ID)
strFileLocation=Server.MapPath(strFilePath)
if (strFileName<>"") then call delFile(strFileLocation & "" & strFileName)
call uploadFile(strFileName, strFileLocation, intUploadType)
strFileName=Mid(strFileName,InStrRev(strFileName," ")+1)
end sub %>
<% 'saveDatabase()
sub saveDatabase()
dim sqlSave
if intImage<>6 then
sqlSave = "UPDATE SHOPASP_PRODUCT SET " & _
" PRO_IMAGE" & intImage & "=" & CDBStr(strFileName) & _
" WHERE PRO_ID=" & PRO_ID
call execSQL(sqlSave)
end if
Response.Redirect strLinkSave
end sub %>
</body>
</html>
<script LANGUAGE="javascript">
function InsertImage(txtFile, intImage)
{
var imgPath;
imgPath=txtFile.value;
document.IMAGE_LOCAL.src=imgPath;
}
</script>
---------------------------------------------------------------------
Trong file lib_upload.asp trên là dùng chung cho tất cả các định dạng. Nhưng trong trang quản trị thì mổi định dạng đều có mộ file
upload_produc_htlm.asp dùng để Up file *.html
Mong các cao thủ xuất chiêu chỉ giáo dùm.
Báo là file lib_upload.asp err line 17.
------------------------------------
Đây là nội dung file .
------------------------------------
<%
dim g_intUploadType
g_intUploadType=0
%>
<%
'uploadFile
sub uploadFile(strFileName, strFileLocation, blnUploadType)
'On Error Resume Next
dim objFileSystem
dim objUpload
if blnUploadType=0 then
set objFileSystem = CreateObject("Scripting.FileSystemObject")
if not(objFileSystem.FolderExists(strFileLocation)) then objFileSystem.CreateFolder(strFileLocation)
set objUpload= Server.CreateObject("Persits.Upload.1")
objUpload.SetMaxSize 5000000,true
objUpload.Save(strFileLocation)
strFileName=objUpload.Files("strFileName").Path
elseif blnUploadType=1 then
set objFileSystem = CreateObject("Scripting.FileSystemObject")
if not(objFileSystem.FolderExists(strFileLocation)) then objFileSystem.CreateFolder(strFileLocation)
Set objUpload= Server.CreateObject("SoftArtisans.FileUp")
objUpload.Path=strFileLocation
objUpload.Form("strFileName").Save
strFileName=objUpload.Form("strFileName").ServerNa me
end if
if (Err.number<>0) then
Response.Write Err.description
end if
end sub %>
<%'delFolder
sub delFolder(FolderPath)
dim objFileSystem, strFolderPath
set objFileSystem = CreateObject("Scripting.FileSystemObject")
if FolderPath <> "" then
strFolderPath=server.MapPath(FolderPath)
if objFileSystem.FolderExists(strFolderPath) then objFileSystem.DeleteFolder(strFolderPath)
end if
end sub
%>
<% 'del file
function delFile(strSource)
dim objFileSystem
dim fsFile
on error resume next
set objFileSystem=CreateObject("Scripting.FileSystemOb ject")
set fsFile=objFileSystem.GetFile(strSource)
fsFile.Delete true
end function
%>
<% sub uploadFile1(file1, file2, file3, file4, file5, file6, file7, file8, file9, file10, strFileLocation)
On Error Resume Next
dim fs
dim objUpload
if g_intUploadType=0 then
set fs = CreateObject("Scripting.FileSystemObject")
if not(fs.FolderExists(strFileLocation)) then fs.CreateFolder(strFileLocation)
set objUpload= Server.CreateObject("Persits.Upload.1")
objUpload.SetMaxSize 5000000,true
objUpload.Save(strFileLocation)
file1=objUpload.Files("file1").Path
file2=objUpload.Files("file2").Path
file3=objUpload.Files("file3").Path
file4=objUpload.Files("file4").Path
file5=objUpload.Files("file5").Path
file6=objUpload.Files("file6").Path
file7=objUpload.Files("file7").Path
file8=objUpload.Files("file8").Path
file9=objUpload.Files("file9").Path
file10=objUpload.Files("file10").Path
elseif g_intUploadType=1 then
set fs = CreateObject("Scripting.FileSystemObject")
if not(fs.FolderExists(strFileLocation)) then fs.CreateFolder(strFileLocation)
Set objUpload= Server.CreateObject("SoftArtisans.FileUp")
objUpload.Path=strFileLocation
objUpload.Form("file1").Save
objUpload.Form("file2").Save
objUpload.Form("file3").Save
objUpload.Form("file4").Save
objUpload.Form("file5").Save
objUpload.Form("file6").Save
objUpload.Form("file7").Save
objUpload.Form("file8").Save
objUpload.Form("file9").Save
objUpload.Form("file10").Save
file1=objUpload.Form("file1").ServerName
file2=objUpload.Form("file2").ServerName
file3=objUpload.Form("file3").ServerName
file4=objUpload.Form("file4").ServerName
file5=objUpload.Form("file5").ServerName
file6=objUpload.Form("file6").ServerName
file7=objUpload.Form("file7").ServerName
file8=objUpload.Form("file8").ServerName
file9=objUpload.Form("file9").ServerName
file10=objUpload.Form("file10").ServerName
end if
if (Err.number<>0) then
Response.Write Err.description
end if
end sub %>
-----------------------------------------------------------------------
Và file produc_upload_images.asp
Sau đây là nội dung file
-----------------------------------------------------------------------
<!--#include file="../include/lib_init.asp"-->
<!--#include file="../include/lib_utilities.asp"-->
<!--#include file="../include/lib_manager.asp"-->
<!--#include file="../include/lib_database.asp"-->
<!--#include file="../include/lib_grid.asp"-->
<!--#include file="../include/lib_form.asp"-->
<!--#include file="../include/lib_upload.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Upload hinh anh</title>
<link rel="stylesheet" type="text/css" href="style_manager.css">
<link rel="stylesheet" type="text/css" href="style_grid.css">
</head>
<script language="javascript" src="../ClientScripts/Utilities.js"></script>
<script language="javascript" src="../ClientScripts/Utilities_manager.js"></script>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<% g_intSubHighlight=100 %>
<!--#include file="header_product.asp"-->
<% 'main content
dim PRO_ID, PRO_IMAGE1, PRO_IMAGE2, PRO_IMAGE3, PRO_IMAGE4, PRO_IMAGE5
dim intImage, strCatImage, strFileName, strFileNameTemp, strSql
dim strAction, strName, strCaption, strTitleForm
dim strLinkBack, strLinkSave, strLinkDelete
dim intPageStatus
dim strGetImage, strTmpCatImage
PRO_ID=getNumberValid(Request("PRO_ID"),0)
if (PRO_ID=0) then Response.Redirect "default.asp"
intImage=getNumberValid(Request("image_id"),0)
strAction="product_upload_image.asp?image_id=" & intImage & "&pro_id=" & PRO_ID
strTitleForm="Upload hinh anh"
strLinkBack="product_upload_list.asp?pro_id=" & PRO_ID
strLinkSave="product_upload_list.asp?pro_id=" & PRO_ID
if intImage<>6 then
strSql=" SELECT PRO_IMAGE" & intImage & " FROM SHOPASP_PRODUCT WHERE PRO_ID=" & PRO_ID
strFileName=getSingleValue(strSql)
strFileNameTemp=strFileName
end if
if Request.ServerVariables("request_method")="POST" then
call uploadFileLocal(g_intUploadType)
call saveDatabase()
else
Select case intImage
Case 1 strTmpCatImage="Hình minh họa nhỏ"
Case 2 strTmpCatImage="Hình minh họa lớn"
Case 3 strTmpCatImage="Hình ảnh chi tiết"
Case 4 strTmpCatImage="Hình ảnh 4"
Case 5 strTmpCatImage="Hình ảnh 5"
Case 6 strTmpCatImage="File kèm theo file HTML"
End Select
call showProduct(PRO_ID)
call showForm()
end if
%>
<!--#include file="footer.asp"-->
<% 'showForm()
sub showForm() %>
<table border="0" cellspacing="1" cellpadding="3" class="tdGridTable" align="center">
<form action="<%=strAction%>" ENCTYPE="MULTIPART/FORM-DATA" method="POST" name="frmUpload" id="frmUpload">
<tr>
<td class="tdGridTitle" colspan="2">
<%=strTitleForm%>
<% if not(IsNaS(strLinkBack)) then %> <a href="<%=strLinkBack%>"><span class="linkAdd">Back</span></a> <% end if %>
</td>
</tr>
<tr class="tdGridRow">
<td><b><%call showStringUnicode(strTmpCatImage)%>:</b></td>
<td><input type="file" name="strFileName" id="strFileName" size="50" onchange="InsertImage(this)"></td>
</tr>
<% dim path: path=getPathProduct(PRO_ID)%>
<% call showFieldInput (strTmpCatImage & " (local):", "IMAGE_LOCAL", "image", "", "", 0, 0 , 0, false, false, false) %>
<% call showFieldInput (strTmpCatImage & ":", "IMAGE_SERVER", "image", "", path & strFileName, 0, 0 , 0, false, false, false) %>
<tr>
<td class="tdGridTitle" colspan="2">
<% call showSaveResetBackButton()%>
</td>
</tr>
</form>
</table>
<% end sub %>
<% 'uploadFileLocal
sub uploadFileLocal(intUploadType)
dim strFilePath, strFileLocation
strFilePath=getPathProduct(PRO_ID)
strFileLocation=Server.MapPath(strFilePath)
if (strFileName<>"") then call delFile(strFileLocation & "" & strFileName)
call uploadFile(strFileName, strFileLocation, intUploadType)
strFileName=Mid(strFileName,InStrRev(strFileName," ")+1)
end sub %>
<% 'saveDatabase()
sub saveDatabase()
dim sqlSave
if intImage<>6 then
sqlSave = "UPDATE SHOPASP_PRODUCT SET " & _
" PRO_IMAGE" & intImage & "=" & CDBStr(strFileName) & _
" WHERE PRO_ID=" & PRO_ID
call execSQL(sqlSave)
end if
Response.Redirect strLinkSave
end sub %>
</body>
</html>
<script LANGUAGE="javascript">
function InsertImage(txtFile, intImage)
{
var imgPath;
imgPath=txtFile.value;
document.IMAGE_LOCAL.src=imgPath;
}
</script>
---------------------------------------------------------------------
Trong file lib_upload.asp trên là dùng chung cho tất cả các định dạng. Nhưng trong trang quản trị thì mổi định dạng đều có mộ file
upload_produc_htlm.asp dùng để Up file *.html
Mong các cao thủ xuất chiêu chỉ giáo dùm.
Bài liên quan
ối trời ơi nhìn vào hoa cả mắt luôn bác đánh dấu cho em line 17 đó nằm đâu và tên lỗi như nào may ra em còn đoán được chứ bác đưa cả đống đó lên thế này thì đến bố em cũng không thể biết được. mà nhất là thông báo lỗi gì chi tiết càng tốt (à nếu có cái error number ấy bác đưa ra được là tốt nhất.)
set objUpload= Server.CreateObject("Persits.Upload.1")
-----------------------------------------------------------------------------------
The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.
--------------------------------------------------------------------------------
Please try the following:
Click the Refresh button, or try again later.
Open the localhost home page, and then look for links to the information you want.
HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services
--------------------------------------------------------------------------------
Technical Information (for support personnel)
Error Type:
Server object, ASP 0177 (0x800401F3)
Invalid class string
/phuongnam/include/lib_upload.asp, line 17
Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705)
Page:
POST 4464 bytes to /phuongnam/pncquantrithongtin/product_upload_image.asp
POST Data:
. . .
Time:
Tuesday, May 10, 2005, 9:35:09 AM
More information:
Microsoft Support
Không ai trả lời giúp sao? đang cần gấm lắm pà kon ơi!
modMimeFunctions.asp
Mong bác giúp cho.
Nếu có bác nào biết Up cho tui phát nhé, cám ơn các bác trước.
Persit Upload cái này là ActiveX phải mua của Artisoft (quên tên rồi).
Khi thấy cái này: set objUpload= Server.CreateObject("Persits.Upload.1")
là mình đoán ngay là ActiveX rồi.
ASP bên windows không có chức năng upload, vì vậy người ta phải mua thêm cái ActiveX này cài vô server mới upload files được.
Nếu kiếm không ra cái này bạn có thểm kiếm cái VBScript hình như gọi là pure ASP Upload cũng có thể upload ngon lành (bạn google search thử coi).