上传的图片怎么保存到服务器指定的目录并获取完整路径?

nnlyc 2004-08-01 10:53:52
已经实现图片上传并保存在
C:\Inetpub\wwwroot\myweb\source\images,

怎么才能保存到服务器其它分区比如d:\images\下,并取得完整的路径"d:\images\a.jpg"?
...全文
396 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fly_miss 2004-08-01
  • 打赏
  • 举报
回复
Private Sub BtnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnUpload.Click
Dim postPath As String
Dim myFile As HttpPostedFile
Dim serverPath As String
Dim serverName As String
Dim tmpName, erroutput As String
Dim fileExtn As String

If Not filUpload.PostedFile Is Nothing Then

myFile = filUpload.PostedFile
Dim fnFileLen As Integer = myFile.ContentLength
If fnFileLen = 0 Then
erroutput = myinfo.Deal_Info("errstring", "Error Information", 14)
Page.RegisterStartupScript("1", "<script>" & erroutput & "</script>")
Exit Sub
End If
'Check the file !
Dim strExt As String() = New String(5) {".gif", ".jpg", ".jpeg", ".jpe", ".bmp", ".png"}
Dim strExtensions As String = System.IO.Path.GetExtension(myFile.FileName).Trim.ToLower
If (Array.IndexOf(strExt, strExtensions) = -1) Then
erroutput = myinfo.Deal_Info("errstring", "Error Information", 15)
Page.RegisterStartupScript("1", "<script>" & erroutput & "</script>")
Exit Sub
Else
errMsg.Text = ""
End If

If myAttach(myFile, tmpDir) = False Then
Exit Sub
Else
erroutput = myinfo.Deal_Info("errstring", "Error Information", 16)
Page.RegisterStartupScript("1", "<script>" & erroutput & "</script>")
Exit Sub
End If
'System.IO.File.Move(imgFile.ImageUrl, Server.MapPath("dbimg/" & filename.Value))
'imgFile.ImageUrl = Server.MapPath("dbimg/" & filename.Value)
End If
End Sub

'=================================================
Public Function myAttach(ByVal htpFile As HttpPostedFile, ByVal strSavePath As String) As Boolean
Dim tmpDir As String
Try
Dim saveFile As String
filename.Value = myRandom() & System.IO.Path.GetExtension(htpFile.FileName)
saveFile = txtPath.Value & filename.Value
While System.IO.File.Exists(saveFile)
filename.Value = myRandom() & System.IO.Path.GetExtension(htpFile.FileName)
saveFile = txtPath.Value & filename.Value
End While
htpFile.SaveAs(saveFile)
imgFile.ImageUrl = "tmp\" & filename.Value
'imgFile.ImageUrl = ResolveUrl(saveFile)
' errMsg.Text = "<b><font color=red>" & "Upload Success ! please Save" & "</font></b>"
Return True
Catch exp As Exception
errMsg.Text = exp.ToString()
Return False
End Try
End Function
'=================================================
rexsp 2004-08-01
  • 打赏
  • 举报
回复
拷贝过去就好了。
程序很容易实现了。。
lxp76 2004-08-01
  • 打赏
  • 举报
回复
new System.IO.FileInfo(Server.MapPath(Request.ApplicationPath)+"你的文件名.***(后缀)")

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧