2013-03-01 73 views
2

我不是一個程序員,所以我很抱歉在這個問題上我可能沒有任何理解。我一直在挖掘所有代碼,但我無法弄清楚這一點。 該網站是一個asp.net網站。編譯時除了高度之外沒有錯誤,不適用。我正在使用共享主機,因此我無法訪問系統文件。上傳後臨時存儲的圖像在哪裏?

一位客戶將圖像上傳到我們的網站,供我們處理和打印他們訂購的任何產品。圖像不會出現在服務器上的任何地方,直到他們點擊繼續付款按鈕。我已經下載整個網站前後驗證文件夾大小。

在將圖像實際存儲爲.jpg之前,圖像在哪裏臨時存儲?

</asp:UpdatePanel> 
    <asp:Button CssClass="Buttons" ID="Button1" 
     style="font-weight: bold; color: white; background-color: #336699;" 
     runat="server" OnClick="AddToCartButton_Click" 
     Text="Upload Image and Add To Cart" 
     CommandArgument="ObjectDataSourceEventArgs" /> 
&nbsp; 
<div style="width:800px"> 
    <br /> 
    Larger files may take a minute or two to upload 
    <asp:Label ID="lblLimitReached" runat="server" 
     Visible="false" STYLE="color:Red" Text=""> 
    </asp:Label> 
</div> 
<br /><hr /><br /> 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderStyle="Solid" 
    Caption="Shopping Cart" CellPadding="4" DataSourceID="ShoppingCartDataSource" 
    ForeColor="#333333" GridLines="Vertical" CaptionAlign="Top" OnRowDeleting="GridView1_RowDeleting"> 
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> 
    <Columns> 
     <asp:BoundField DataField="OriginalImageName" HeaderText="Image" SortExpression="OriginalImageName" /> 
     <asp:BoundField DataField="SizePrice" HeaderText="Size/Price" SortExpression="SizePrice" /> 
     <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" /> 
     <asp:BoundField DataField="MountedString" HeaderText="Mounted" SortExpression="Mounted" /> 
     <asp:BoundField DataField="DigitalString" HeaderText="Digital Frame" SortExpression="DigitalFrame" /> 
     <asp:BoundField DataField="BWString" HeaderText="Black &amp; White" SortExpression="BlackAndWhite" /> 
     <asp:BoundField DataField="PriceString" HeaderText="Price" ReadOnly="True" SortExpression="PriceString" /> 
     <asp:CommandField ButtonType="Button" ShowDeleteButton="True" /> 
    </Columns> 
    <RowStyle BackColor="#EFF3FB" /> 
    <EditRowStyle BackColor="#2461BF" /> 
    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> 
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> 
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> 
    <AlternatingRowStyle BackColor="White" /> 
</asp:GridView> 
<asp:ObjectDataSource ID="ShoppingCartDataSource" runat="server" DataObjectTypeName="ImageInfo" 
    DeleteMethod="DeleteData" InsertMethod="InsertData" SelectMethod="SelectData" 
    TypeName="ImageInfoCollection" UpdateMethod="UpdateData" OnObjectCreating="ShoppingCartDataSource_ObjectCreating" ></asp:ObjectDataSource> 
<hr /><br /> 
<asp:Label ID="TotalPriceLabel" runat="server" style="display:inline" Text="Current total: $0.00" Width="162px"></asp:Label> 
    <br /> 
<asp:Button CssClass="Buttons" ID="CheckOutButton" runat="server" 
    Text="Go To Check Out" CausesValidation="False" 
    OnClick="PlaceOrderButton_Click" 
    style="font-weight: bold; color: white; background-color: #336699;" 
    Visible="False" /><br /> 
<asp:Label ID="FreeShipLabel" runat="server" ForeColor="#FF0033"></asp:Label><br /> 
<asp:XmlDataSource ID="ImageSizeDataSource" runat="server" DataFile="~/App_Data/ImageSizeData.xml"></asp:XmlDataSource> 
<asp:RequiredFieldValidator ID="ImagePathValidator" runat="server" ControlToValidate="FileUpload1" 
    ErrorMessage="Please select an image to upload." Display="None"></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="FileUploadTypeValidator" runat="server" ControlToValidate="FileUpload1" 
    Display="None" ErrorMessage="Please upload only files of type jpg (or jpeg)." 
    ValidationExpression="(.*\.jpg)|(.*\.jpeg)|(.*\.JPG)|(.*\.JPEG)"></asp:RegularExpressionValidator> 
<asp:RequiredFieldValidator ID="ImageSizeValidator" runat="server" ControlToValidate="SizeDropDownList" 
    ErrorMessage="Please select an image size." Display="None"></asp:RequiredFieldValidator> 
<asp:RequiredFieldValidator ID="QuantityValidator" runat="server" ControlToValidate="QuantityTextBox" 
    ErrorMessage="Please select image quantity." Display="None"></asp:RequiredFieldValidator> 
<asp:RegularExpressionValidator ID="QuantityExpressionValidator" runat="server" ControlToValidate="QuantityTextBox" 
    Display="None" ErrorMessage="Invalid quantity: please choose 1 to 999." ValidationExpression="^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$"></asp:RegularExpressionValidator> 
<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" 
    HeaderText="Something is missing:" Height="40px" ShowMessageBox="True" 
    ShowSummary="False" Width="179px" /> 
<br /> 
<div style="width:800px"> 
    <uc3:Footer ID="Footer1" runat="server" /> 
</div> 
</form> 

這是buynow.aspx.cs

using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
using System.Text; 
using System.Xml; 
using System.Drawing; 

public partial class BuyNow : System.Web.UI.Page 
{ 
const string DFText = "Choose a Digital Frame."; 

/// <summary> 
/// Page_Load 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
protected void Page_Load(object sender, EventArgs e) 
{ 
    Page PP = Page.PreviousPage as ASP.home_aspx; 

    if (!IsPostBack) 
    { 
     ImageInfoCollection ImageInfo = new ImageInfoCollection(); 
     Session["ImageInfoCollection"] = ImageInfo; 
     ResetDefaults(); 
     FreeShipLabel.Text = ""; 
     FileUpload1.Focus(); 
    } 
} 


/// <summary> 
/// AddToCartButton_Click 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
protected void AddToCartButton_Click(object sender, EventArgs e) 
{ 

    ImageInfoCollection Images = (ImageInfoCollection)Session["ImageInfoCollection"]; 
    if (Images == null) { 
     Session["SessionError"] = "No Images on BuyNow->AddToCartButton_Click"; 
     Response.Redirect("Error.aspx"); 
    } 


    if (Images.Count >= 20) 
    { 
     lblLimitReached.Text = "Only 20 Images allowed per order...Please place another order"; 
     lblLimitReached.Visible = true; 
     return; 
    } 
    /// BUG: need to figure out how to handle the Back Button case 

    if (DigitalFramesCheckBox.Checked && (DigitalFrameLabel.Text == "" || DigitalFrameLabel.Text == DFText)) 
     return; 

    ImageInfo Image = CreateImageInfoFromPage(); 
    if (Image == null) 
     return; 

    Images.InsertData(Image); 
    Session["ImageInfoCollection"] = Images; 
    ShoppingCartDataSource.Select(); 

    GridView1.DataBind(); // update the GridView shopping cart 
    TotalPriceLabel.Text = "Current Total: " + CalculateCartPrice(Images); 
    ResetDefaults(); 

    if (Images.FreeShipping()) 
     FreeShipLabel.Text = "Order Qualifies for Free Shipping."; 
    else 
     FreeShipLabel.Text = ""; 

    if (Images.Count > 0) 
     CheckOutButton.Visible = true; 

} 


/// <summary> 
/// ShoppingCartDataSource_ObjectCreating 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
protected void ShoppingCartDataSource_ObjectCreating(object sender, ObjectDataSourceEventArgs e) 
{ 
    // Code that runs when a new session is started 
    ImageInfoCollection Images = (ImageInfoCollection)Session["ImageInfoCollection"]; 
    if (Images == null) { 
     Session["SessionError"] = "No Images on ShoppingCartDataSource_ObjectCreating"; 
     Response.Redirect("Error.aspx"); 
    } 

    e.ObjectInstance = Images; 
} 

/// <summary> 
/// GridView1_RowDeleting 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) 
{ 
    ImageInfoCollection Images = (ImageInfoCollection)Session["ImageInfoCollection"]; 
    if (Images == null) 
     return; 

    Images.DeleteData(e.RowIndex); 
    Session["ImageInfoCollection"] = Images; 

    TotalPriceLabel.Text = "Current Total: " + CalculateCartPrice(Images); 

    if (Images.FreeShipping()) 
     FreeShipLabel.Text = "Order Qualifies for Free Shipping."; 
    else 
     FreeShipLabel.Text = ""; 

    if (Images.Count == 0) 
     CheckOutButton.Visible = false; 
} 

/// <summary> 
/// SizeDropDownList_SelectedIndexChanged 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
protected void SizeDropDownList_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    // read the xml file to determine image size attributes 
    int index = SizeDropDownList.SelectedIndex; 
    ImageXmlAttributes Attrs = new ImageXmlAttributes(ImageSizeDataSource); 
    Attrs.LoadByIndex(index); 

    // translate the attributes into controls for the page 
    // QuantityListBox.Text = Convert.ToString(Attrs.Quantity); 
    if (Attrs.MountingAvailable) { 
     MountingCheckBox.Enabled = true; 
     MountingPriceLabel.Enabled = true; 
     MountingPriceLabel.Text = "$" + Convert.ToString(Attrs.MountingPrice); 
    } 
    else { 
     MountingCheckBox.Enabled = false; 
     MountingCheckBox.Checked = false; 
     MountingPriceLabel.Enabled = false; 
     MountingPriceLabel.Text = ""; 
    } 

    if (Attrs.DigitalAvailable) { 
     DigitalFramesCheckBox.Enabled = true; 
     DigitalFrameLabel.Text = ""; 
    } 
    else { 
     DigitalFramesCheckBox.Enabled = false; 
     DigitalFramesCheckBox.Checked = false; 
     DigitalFramePanel.Visible = false; 
     DigitalFrameLabel.Text = ""; 
    } 

    if (Attrs.BWAvailable) 
     BlackAndWhiteCheckBox.Enabled = true; 
    else { 
     BlackAndWhiteCheckBox.Enabled = false; 
     BlackAndWhiteCheckBox.Checked = false; 
    } 

    CardPanel.Visible = false; 

    if ((SizeDropDownList.Text == "DLCCU1") || (SizeDropDownList.Text == "DLCCU2") || (SizeDropDownList.Text == "DLCCU3")) 
    { 
     CardPanel.Visible = true; 
    } 
} 

protected void MountingCheckBox_CheckedChanged(object sender, EventArgs e) 
{ 
    if (!MountingCheckBox.Checked) 
     MountingPriceLabel.Text = ""; 
    else { 
     // read the xml file to determine image size attributes 
     int index = SizeDropDownList.SelectedIndex; 
     ImageXmlAttributes Attrs = new ImageXmlAttributes(ImageSizeDataSource); 
     Attrs.LoadByIndex(index); 
     MountingPriceLabel.Text = "$" + Convert.ToString(Attrs.MountingPrice); 
    } 
} 

/// <summary> 
/// PlaceOrderButton_Click 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
protected void PlaceOrderButton_Click(object sender, EventArgs e) 
{ 
    Response.Redirect("~/CustomerInfo.aspx"); 
} 

/// <summary> 
/// CreateImageFromPage 
/// </summary> 
/// <returns></returns> 
private ImageInfo CreateImageInfoFromPage() 
{ 
    ImageInfo Image = new ImageInfo(ImageSizeDataSource); 
    Image.MyFileUpload = FileUpload1; 
    Image.OriginalImageName = FileUpload1.FileName; 
    Image.Mounted = MountingCheckBox.Checked; 
    Image.BlackAndWhite = BlackAndWhiteCheckBox.Checked; 

    Image.DigitalFrame = DigitalFramesCheckBox.Checked; 
    Image.DigitalFrameID = DigitalFrameLabel.Text; 

    Image.Quantity = Convert.ToInt32(QuantityTextBox.Text); 
    Image.LoadAttributes(SizeDropDownList.SelectedIndex); 
    return Image; 
} 

/// <summary> 
/// ResetDefaults 
/// </summary> 
private void ResetDefaults() 
{ 
    SizeDropDownList.ClearSelection(); 
    QuantityTextBox.Text = "1"; 
    MountingCheckBox.Checked = false; 
    MountingPriceLabel.Text = ""; 
    MountingCheckBox.Enabled = true; 
    BlackAndWhiteCheckBox.Checked = false; 
    BlackAndWhiteCheckBox.Enabled = true; 
    DigitalFramesCheckBox.Checked = false; 
    DigitalFramesCheckBox.Enabled = true; 
    DigitalFramePanel.Visible = false; 
    CardPanel.Visible = false; 
    CardPanel.Visible = false; 
    DigitalFrameLabel.Text = ""; 
    DigitalFrameLabel.ForeColor = Color.Black; 
} 

/// <summary> 
/// CalculateCartPrice 
/// </summary> 
/// <param name="Images"></param> 
/// <returns></returns> 
private static string CalculateCartPrice(ImageInfoCollection Images) 
{ 
    return Images.GetTotalPriceString(); 
} 

protected void DigitalFramesCheckBox_CheckedChanged(object sender, EventArgs e) 
{ 
    TurnOffAllRadioButtons(); 
    if (DigitalFramesCheckBox.Checked == true) { 
     DigitalFramePanel.Visible = true; 
     DigitalFrameLabel.Text = DFText; 
     DigitalFrameLabel.ForeColor = Color.Red; 
     SizeDropDownList.SelectedValue = "DL20U"; 
     BlackAndWhiteCheckBox.Checked = false; 
     BlackAndWhiteCheckBox.Enabled = false; 
    } 
    else { 
     DigitalFramePanel.Visible = false; 
     DigitalFrameLabel.ForeColor = Color.Black; 
     DigitalFrameLabel.Text = ""; 
     SizeDropDownList.SelectedValue = ""; 
     BlackAndWhiteCheckBox.Checked = false; 
     BlackAndWhiteCheckBox.Enabled = true; 
    } 
} 

protected void RadioButtonF1_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF1, e); 
} 

protected void RadioButtonF2_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF2, e); 
} 

protected void RadioButtonF3_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF3, e); 
} 

protected void RadioButtonF4_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF4, e); 
} 

protected void RadioButtonF5_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF5, e); 
} 

protected void RadioButtonF6_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF6, e); 
} 

protected void RadioButtonF7_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF7, e); 
} 

protected void RadioButtonF8_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF8, e); 
} 

protected void RadioButtonF9_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF9, e); 
} 

protected void RadioButtonF13_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF13, e); 
} 

protected void RadioButton15_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF15, e); 
} 

protected void RadioButtonF16_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF16, e); 
} 

protected void RadioButtonF17_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF17, e); 
} 

protected void RadioButtonF18_CheckedChanged(object sender, EventArgs e) 
{ 
    SelectRadioButton(RadioButtonF18, e); 
} 

private void SelectRadioButton(RadioButton RB, EventArgs e) 
{ 
    TurnOffAllRadioButtons(); 
    RB.Checked = true; 
    DigitalFrameLabel.Text = RB.ToolTip; 
    DigitalFrameLabel.ForeColor = Color.Black; 
} 

private void TurnOffAllRadioButtons() 
{ 
    RadioButtonF1.Checked = false; 
    RadioButtonF2.Checked = false; 
    RadioButtonF3.Checked = false; 
    RadioButtonF4.Checked = false; 
    RadioButtonF5.Checked = false; 
    RadioButtonF6.Checked = false; 
    RadioButtonF7.Checked = false; 
    RadioButtonF8.Checked = false; 
    RadioButtonF9.Checked = false; 
    RadioButtonF1.Checked = false; 
    RadioButtonF13.Checked = false; 
    RadioButtonF15.Checked = false; 
    RadioButtonF16.Checked = false; 
    RadioButtonF17.Checked = false; 
    RadioButtonF18.Checked = false; 
} 

protected void BlackAndWhiteCheckBox_CheckedChanged(object sender, EventArgs e) 
{ 
    if (BlackAndWhiteCheckBox.Checked) { 
     DigitalFramesCheckBox.Checked = false; 
     DigitalFramesCheckBox.Enabled = false; 
    } 
    else { 
     if ((SizeDropDownList.SelectedValue == "DL20U") || (SizeDropDownList.SelectedValue == "")) 
     { 
      DigitalFramesCheckBox.Enabled = true; 
      DigitalFramesCheckBox.Checked = false; 
     } 
    } 
} 

}

回答

1

以下行是該問題:

Images.InsertData(Image); 
    Session["ImageInfoCollection"] = Images; 
    ShoppingCartDataSource.Select(); 

基本上,圖像時上傳他們是存儲在會話對象中。這意味着它會直接進入Web服務器RAM並呆在那裏。這是一個非常糟糕的主意,特別是對於期望任何類型負載的服務器而言。順便說一句,爲什麼它很糟糕的原因是它會導致RAM使用量的大量增加,並且如果Web應用程序需要回收(這種情況很可能在這種情況下經常發生),則存儲在會話中的所有圖像都將丟失。

這需要更改爲將圖像推送到數據庫或磁盤上的臨時文件。無論哪種方式,這是如何編碼意味着你不會看到文件系統上顯示的任何文件,直到它們從會話轉移到磁盤。

+0

的網站是https://www.digilarge.com/如果您嘗試上傳圖片,請確保它是一個大圖片,以便您可以注意它何時實際上傳。 – Computationalerr 2013-03-01 18:19:46

+0

@Computationalerr:查看更新。 – NotMe 2013-03-01 20:51:05

+0

非常感謝Chris。你願意爲我提供一個解決辦法嗎?如果你喜歡,私下給我發消息。克里斯在肖像快遞公司com – Computationalerr 2013-03-01 21:01:21

-1

當您使用像文件上傳這樣的控件時,上傳的文件將被放置在Web應用程序服務器某處的臨時文件夾中。它放在哪裏並不重要,因爲asp.net提供了一個可供使用的對象。例如:

<asp:FileUpload ID="FileUpload" runat="server" Height="24px" Style="position: static" Width="255px" /> 
<asp:Button ID="Uploadbtn" runat="server" OnClick="Uploadbtn_Click" Style="position: static" Text="Upload" Width="82px" /> 

該控件創建典型的上傳控件。它有一個瀏覽按鈕和一個上傳按鈕。當用戶點擊上傳按鈕,你將有一個事件的方法是這樣的:

Protected Sub Uploadbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
    Dim myUploadeObject As HttpPostedFile 
    myUploadeObject = Me.FileUpload.PostedFile  
End Sub 

的HttpPostedFile對象有一大堆,你可以訪問方法和屬性,如文件名,輸入流,內容類型和長度。

此外,FileUpload對象本身具有許多有用的特性以及類似的方法:HasFile,文件名,文件的字節和內容

把它們放在一起,你可以做這樣的事情:

Protected Sub Uploadbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
    Dim fu As FileUpload 
    fu = Me.FileUpload 

    If (fu.HasFile = True) Then 
     Dim myUploadeObject As HttpPostedFile 
     myUploadeObject = Me.FileUpload.PostedFile 

     Dim filePath As String = myUploadeObject.FileName 
     Dim fileName As String = fu.FileName 
     Dim fileBytes As Byte() = fu.FileBytes 
     Dim fileContenetType As String = myUploadeObject.ContentType 
     Dim inputStream As IO.FileStream = myUploadeObject.InputStream 

    Else 
     'there was a problem, alert the user 
    End If  
End Sub 
相關問題