PDA

View Full Version : مشکل در نمایش تصویر روی سایت



jigily
یک شنبه 30 مهر 1391, 17:57 عصر
تصویرها وقتی روی هاست نیست نمایش داده میشه اما روی هاست نشون نمیده؟؟

meisam3322
یک شنبه 30 مهر 1391, 20:13 عصر
در هر حال آدرسهای تصاویر شما اشتباه هستند. حداقل تگ های img خودتون رو بذارین تا مشخص بشه چه کاری رو انجام دادین .

jigily
دوشنبه 01 آبان 1391, 20:39 عصر
من از این کد استفاده میکنم

string dir = Server.MapPath(".") + "\\img\\";
//چک کردن پسوند فایل
string[] extention = { ".jpg", ".png", ".gif" };
string fileextention = System.IO.Path.GetExtension(FileUpload1.PostedFile .FileName);
if (Array.IndexOf(extention, fileextention.ToLower()) < 0)
{
lblUpladMS.Text = "فایل شما معتبر نیست";
return;
}

long size = FileUpload1.PostedFile.ContentLength;
size = size / 1024;
if (size > 70)
{
lblUpladMS.Text = "فایل باید کوچکتر از70 کیلو بایت باشد";
return;
}

string name = System.IO.Path.GetFileName(FileUpload1.PostedFile. FileName);
if (System.IO.File.Exists(dir + "\\" + name))
{
string tempName = name;
int i = 0;
while (System.IO.File.Exists(dir + "\\" + tempName))
{
i++;
tempName = "(" + i.ToString() + ")" + tempName;
}
name = "(" + i.ToString() + ")" + name;
}
//تعیین نوع حقیقی فایل
string filetype = FileUpload1.PostedFile.ContentType.ToString();
if (filetype == "image/x-png" || filetype == "image/gif" || filetype == "image/pjpeg")
{
FileUpload1.PostedFile.SaveAs(dir + name);
obja.PicName = name;
obja.PicUrl = "~/img/" + name;

}


تا وقتی روی ویندوز و لوکال هاست اجرا میشه عکس ها را نمایش میده ام روی هاست نه؟

Mag-Mag
دوشنبه 01 آبان 1391, 21:00 عصر
اینو تست کن
بجای

string dir = Server.MapPath(".") + "\\img\\";


بنویس

string dir = Server.MapPath("~") + "\\img\\";


یا

string dir = Server.MapPath("~/img/");

jigily
سه شنبه 02 آبان 1391, 15:51 عصر
مشکل حل نشد

jigily
چهارشنبه 03 آبان 1391, 10:23 صبح
وقتی روی عکس propertise رو میزنم no availble
هست.

jigily
شنبه 06 آبان 1391, 13:42 عصر
کسی نمیدونه باید چکار کنم؟؟
من همه راه هایی که توی سایت گفته شده رفتم اما جواب نداد:گریه:

fakhravari
شنبه 06 آبان 1391, 14:44 عصر
در پست 3 که ذخیره است.
برای نمایش چه کدی استفاده میکنی؟
Image1.ImageUrl = "../Img/Profile_User/"

jigily
شنبه 06 آبان 1391, 21:45 عصر
من از دیتالیست استفاده میکنم که توش از یک image استفاده می کنم و مقدار imgurl اون را <%# EVal("image"
میزارم

jigily
یک شنبه 07 آبان 1391, 19:50 عصر
باید چکار کنم؟

jigily
دوشنبه 08 آبان 1391, 15:12 عصر
اصلا عکس روی هاست ذخیره نمیشه که بخواد نشان بده؟؟؟چجوری باید روی هاست ذخیره اش کنم؟

fakhravari
دوشنبه 08 آبان 1391, 21:37 عصر
برسی کنید ببنید پوشه قابلیت write داره

jigily
چهارشنبه 10 آبان 1391, 13:02 عصر
چطوری این کار کنم؟

jigily
دوشنبه 15 آبان 1391, 16:42 عصر
این کار کردم نداشت allow کردم اما بازم نشد

jigily
چهارشنبه 17 آبان 1391, 14:49 عصر
راه دحل دیگه چیه؟

fakhravari
چهارشنبه 17 آبان 1391, 14:58 عصر
پوشه img در root
public string UpPath;
public string pathImage;
public static string ImageFileName;

public string pathAtach;
public static string AtachFileName;


public void uploadpic()
{

UpPath = Server.MapPath(@"img/");
if (!Directory.Exists(UpPath))
{
Directory.CreateDirectory(Server.MapPath(@"img/"));
}

pathImage = Server.MapPath(@"img/");
String[] validext = { ".jpg", ".jpeg", ".bmp", ".jpe", ".png", ".gif", ".tiff", ".tif", ".bmp" };
string ext = System.IO.Path.GetExtension(FileUpload1.PostedFile .FileName);
if (Array.IndexOf(validext, ext.ToLower()) < 0)
{
return;
}

ImageFileName = System.IO.Path.GetFileName(FileUpload1.FileName);


while (System.IO.File.Exists(pathImage + ImageFileName))
{
ImageFileName = "1" + ImageFileName;
}


FileUpload1.PostedFile.SaveAs(pathImage + ImageFileName);
}



protected string SqlAdd = "INSERT INTO [news] ([title], [img], [comennt]) VALUES (@title, @img, @comennt)";
public string lasteror;


protected void Button2_Click(object sender, EventArgs e)
{

if (FileUpload1.HasFile)
{
uploadpic();

try
{
SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrin gs["ConnectionString1"].ConnectionString);
con1.Open();
SqlCommand cmd1 = new SqlCommand(SqlAdd, con1);
cmd1.CommandType = CommandType.Text;
cmd1.Parameters.Add("@title", SqlDbType.NVarChar).Value = TextBox1.Text;
cmd1.Parameters.Add("@img", SqlDbType.NVarChar).Value = ImageFileName;
cmd1.Parameters.Add("@comennt", SqlDbType.NVarChar).Value = CKEditor1.Text;
cmd1.ExecuteNonQuery();
con1.Close();
this.lasteror = "اطلاعات ثبت شد";
Label1.Text = lasteror;
}

catch
{
this.lasteror = "اشکال در ثبت اطلاعات";
Label1.Text = lasteror;
}
}
else
{
Label1.Text = "انتخاب عکس";
}
}


<asp:GridView ID="GridView4" runat="server"
AutoGenerateColumns="False" ShowHeader="False" BorderStyle="None" GridLines="None"
ShowHeaderWhenEmpty="True"
Width="100%" PageSize="4">
<Columns>
<asp:TemplateField>
<ItemTemplate>


<div id=post-title><%# Eval("Title")%></div>

<p>
<img src='<%# Eval("img", "img/{0}")%>' style="border-style:solid; border-width:0px; margin:1px; width: 152px; height: 134px;" />
</p>
<p style=" color:#FFFFFF">
<%# Eval("Comennt")%>
</p>
</div>
</div>
<br />

</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

jigily
چهارشنبه 17 آبان 1391, 16:10 عصر
راستش سر در نیاوردم از کدت

black_binary
چهارشنبه 17 آبان 1391, 21:00 عصر
Image1.ImageUrl = "../Img/Profile_User/"


خیلی ساده است فقط کافی
../ را در کل آدرس دهی ات پاک کنی (یه سرچ بزنی توی کدت راحت پیدا میشن)نیاز به ~ ,.... نیست
اینطور روی هاست نمایش داده میشه ولی روی سیستم خودت نه.
نیاز به ~/ ,.... نیست فقط اسم فولدر ونام عکست را برای آدرس دهی بده

jigily
پنج شنبه 18 آبان 1391, 17:19 عصر
من try را برداشتم و خطایی میده که نمی دوچم چیه

Access to the path 'C:\inetpub\vhosts\agahistan.ir\httpdocs\myimg\pho to1360.jpg' is denied.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path 'C:\inetpub\vhosts\agahistan.ir\httpdocs\myimg\pho to1360.jpg' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:

Line 89: }Line 90: string filetype = FileUpload1.PostedFile.ContentType.ToString();Line 91: FileUpload1.PostedFile.SaveAs(dir + name);Line 92: obja.PicName = name;Line 93: obja.PicUrl = "/myimg/" + name;

rana-writes
پنج شنبه 18 آبان 1391, 22:14 عصر
سلام
اين خطا موقع ثبت عكس ايجاد شده؟
در اين حالت كه شما اصلا عكسي ثبت نكردين
اين خطا داره ميگه دسترسي به اين پوشه امكان پذير نيست
پس بايد دسترسي write رو به پوشه myimage بدين

پنل هاستتون چيه؟
توي بعضي از پنلها، كاربرها نميتونن دسترسي به پوشه ها رو ايجاد كنن از پشتيبان هاست بخواين كه كمكتون كنه

موفق باشين

jigily
پنج شنبه 18 آبان 1391, 22:24 عصر
بله allow کردم اما بازهم همون خطا رو میده