■26900 / inTopicNo.10) |
Re[5]: 画像のUPロード時にファイル場所の書き込み |
□投稿者/ 初心者 (167回)-(2008/10/22(Wed) 17:09:12)
|
2008/10/22(Wed) 17:13:24 編集(投稿者) 2008/10/22(Wed) 17:11:00 編集(投稿者) 2008/10/22(Wed) 17:10:42 編集(投稿者)
■No26617 (なちゃ さん) に返信 > 元のファイル名は含めない方がいいでしょう。 > IDはDB側でシーケンスを取るのが多分無難ですね。 > ファイルの属性はテキストボックスとかに入れさせて > DB登録時に同時に入れたらいいと思います。 > お返事ありがとうございます 現在テキストボックスの入力で、ファイル名を変更させてUPできるようになりました。 Jitta さんの言うように
■いつIDを取得するか(テキストボックスに) ■DBにいつ保存させるか等
上記をクリアすればUPページは完成しそうなんですが
*参考URL http://msdn.microsoft.com/ja-jp/library/system.web.ui.webcontrols.fileupload(VS.80).aspx *現在のコード <%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"> Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Specify the path on the server to ' save the uploaded file to. Dim savePath As String = "C:\img\" ' Before attempting to perform operations ' on the file, verify that the FileUpload ' control contains a file. If (FileUpload1.HasFile) Then ' Get the name of the file to upload. Dim fileName As String = FileUpload1.FileName Dim sevefile = TextBox1.Rows Dim jpg = TextBox2.Rows ' Append the name of the file to upload to the path. savePath += TextBox1.Text & TextBox2.Text ' Call the SaveAs method to save the ' uploaded file to the specified path. ' This example does not perform all ' the necessary error checking. ' If a file with the same name ' already exists in the specified path, ' the uploaded file overwrites it. FileUpload1.SaveAs(savePath) ' Notify the user of the name the file ' was saved under. UploadStatusLabel.Text = "Your file was saved as " & TextBox1.Text & TextBox2.Text Else ' Notify the user that a file was not uploaded. UploadStatusLabel.Text = "You did not specify a file to upload." End If
End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub </script>
<html > <head id="Head1" runat="server"> <title>FileUpload Example</title> </head> <body> <form id="form1" runat="server"> <div> <h4>Select a file upload</h4> <h4> <asp:FileUpload id="FileUpload1" runat="server"> </asp:FileUpload> </h4> <h4> Select a File Name<br /> <asp:TextBox ID="TextBox1" runat="server" SkinID="<%$ ConnectionStrings:LocalSqlServer %>"></asp:TextBox> </h4> <h4> Select a File Extension <br /> <asp:TextBox ID="TextBox2" runat="server" ReadOnly="True">.jpg</asp:TextBox></h4> <h4> <br /> <asp:Button id="UploadButton" Text="Upload file" OnClick="UploadButton_Click" runat="server" Width="157px"> </asp:Button> <hr /> <asp:Label id="UploadStatusLabel" runat="server"> </asp:Label> </h4> </div> </form> </body> </html>
どなたかご教授願います
|
|