0
خطا در آپلود عکس
باسلام و احترام
من یک کد برای آپلود عکس در ASP.NET با زبان VB.NET نوشتم . برنامه همه عکسها را آپلود می کنه ولی برخصی از عکسها را آپلود نمی کنه .
علت چی میتونه باشه.
مثلا هر دو عکس با یک گوشی گرفته شده ولی یکی آپلود میشه و دیگری نمیشه.
کد HTML
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
a {
color: #715241;
font-style: normal;
text-decoration: none;
font-size: 20px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="myFileUpload1" runat="server" />
<br />
<asp:Button ID="Button1" runat="server" Text="Upload" onclick="Button1_Click" />
<br />
<!-- To display the Size of image -->
<span>Size Before Resize : </span>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<br />
<span>Size After Resize : </span>
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<br />
<a href="http://localhost:35525/PagesDialog/chPassword.aspx">
<asp:Image ID="imgPersonnel1" runat="server" autocomplete="off" Height="126px"
ImageUrl="~/Images/PicPersonnel.png" Width="126px" />
</a>
<br />
<!-- To display the Resize Image -->
</div>
</form>
</body>
</html>
کد VB.net
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Page.IsValid Then
Dim oHttpPostedFile As System.Web.HttpPostedFile = myFileUpload1.PostedFile
Dim y As String = Request.QueryString("C")
Dim strFileName As String = System.IO.Path.GetFileName(oHttpPostedFile.FileName)
Dim strRootRelativePath As String = "~/pic/"
Dim strPath As String = Server.MapPath(strRootRelativePath)
strFileName = "1.jpg"
Dim strPathName As String = String.Format("{0}\\{1}", strPath, strFileName)
oHttpPostedFile.SaveAs(strPathName)
imgPersonnel1.ImageUrl = ("~/pic/" + strFileName)
imgPersonnel1.ImageAlign = System.Web.UI.WebControls.ImageAlign.AbsMiddle
Dim strInformationMessage As String = "! فایل با موفقیت آپلود گردید"
ClientScript.RegisterStartupScript(Me.[GetType](), "alert", "alert('عکس با موفقیت آپلود گردید')", True)
Return
Response.Redirect(Request.Url.AbsoluteUri)
End If
End Sub
End Class
لینک عکس مورد نظر در لینک زیر قرار دارد.
http://uplod.ir/wl0593rlvuzq/WebApplication1.zip.htm
با تشکر از شما
2 پاسخ
1
با سپاس و تشکر از شما دوست عزیز
بله دقیقا مشکل همین موضوع بود که فرمودید مربوط به حجم بیش از حد مجاز بود که من نیز با نوشتن کد زیر در بخش web.config مشکل حل شد.
<system.web>
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="71200" requestLengthDiskThreshold="51200" executionTimeout="3600" />
</system.web>
0
سلام، ممکنه به دلیل حجم عکس باشه، IIS به صورت پیش فرض محدودیت برای آپلود فایل داره که می تونید بوسیله فایل web.config این حجم رو افزایش یا کاهش بدید:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>