|
|
Rank: Member Groups: Member
Joined: 6/14/2005 Posts: 5 Points: 0
|
Hi all, I am using the sample code to save my images, which is all working well, however I want to save a second thumbnail but the code is not working, My Code Sample Below ================== Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim intFileCount As Integer = CInt(Request.Form("FileCount"))
Dim I As Integer, SourceFile As HttpPostedFile, ThumbnailFile As HttpPostedFile
For I = 1 To intFileCount
SourceFile = Request.Files("SourceFile_" & I)
Dim strFileName As String = Path.GetFileName(SourceFile.FileName)
Dim strNewFileName As String = strFileName
Dim J As Integer = 1
While File.Exists(Server.MapPath(strGalleryPath & Request.Form("albid") & "\" & strNewFileName))
strNewFileName = J & "_" & strFileName
J = J + 1
End While
strFileName = strNewFileName
SourceFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & "\" & strFileName))
If Not Request.Files("Thumbnail1_" & I) Is Nothing Then
ThumbnailFile = Request.Files("Thumbnail1_" & I)
ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & "\" & "Thumbnails/" & strFileName & ".jpg"))
End If
If Not Request.Files("Thumbnail2_" & I) Is Nothing Then
ThumbnailFile = Request.Files("Thumbnail2_" & I)
ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & "\" & "Preview/" & strFileName & ".jpg"))
End If
objAlbum.InsertImagesToAlbum(CInt(Request.Form("albid")), _
CInt(Request.Form("clientid")), _
strFileName, _
CInt(Request.Form("Width_" & I)), _
CInt(Request.Form("Height_" & I)), _
Request.Form("Description_" & I))
Next
End Sub
================== However this is not working, any help would be gratley apperiacted. Thanks Jason Chandler ==================
|
|
 Rank: Advanced Member Groups: Administration
, Member
Joined: 7/28/2003 Posts: 1,254 Points: -345 Location: WA, US
|
Hello Jason, First of all I recommend you to read Debugging Server Scripts topic for general information about debugging. In order to see server page response set ShowDebugWindow property to "True" value. If you use VS.NET then you can run your web project in debug mode and debug it as usual application. If you will receive error trace please post it here, it will help us to solve the problem gracefully. Right now I see the only one incorrect place in you code: you use backslashes in paths when pass them to Server.MapPath method at that time as you should slashes only: >>>>>>>>>>>>> Code:
While File.Exists(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"\"[/b] & strNewFileName))
strNewFileName = J & "_" & strFileName
J = J + 1
End While
strFileName = strNewFileName
SourceFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"\"[/b] & strFileName))
If Not Request.Files("Thumbnail1_" & I) Is Nothing Then
ThumbnailFile = Request.Files("Thumbnail1_" & I)
ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"\"[/b] & "Thumbnails/" & strFileName & ".jpg"))
End If
If Not Request.Files("Thumbnail2_" & I) Is Nothing Then
ThumbnailFile = Request.Files("Thumbnail2_" & I)
ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"\"[/b] & "Preview/" & strFileName & ".jpg"))
End If
<<<<<<<<<<<<< I think here is correct code: >>>>>>>>>>>>> Code:
While File.Exists(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"/"[/b] & strNewFileName))
strNewFileName = J & "_" & strFileName
J = J + 1
End While
strFileName = strNewFileName
SourceFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"/"[/b] & strFileName))
If Not Request.Files("Thumbnail1_" & I) Is Nothing Then
ThumbnailFile = Request.Files("Thumbnail1_" & I)
ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"/"[/b] & "Thumbnails/" & strFileName & ".jpg"))
End If
If Not Request.Files("Thumbnail2_" & I) Is Nothing Then
ThumbnailFile = Request.Files("Thumbnail2_" & I)
ThumbnailFile.SaveAs(Server.MapPath(strGalleryPath & Request.Form("albid") & [b]"/"[/b] & "Preview/" & strFileName & ".jpg"))
End If
<<<<<<<<<<<<<
Best regards, Fedor Skvortsov
|
|
 Rank: Advanced Member Groups: Administration
, Member
Joined: 7/28/2003 Posts: 1,254 Points: -345 Location: WA, US
|
Jason, I also want to notice that the following code can compromise website security in some configuration:
>>>>>>>>> Server.MapPath(strGalleryPath & Request.Form("albid") & "/" & strNewFileName) <<<<<<<<<
Let's assume that malicious user will pass "../../../SomeOtherFolder/" value in albid form field. In this case Server.Math method will return physical path out of strGalleryPath folder. If internet user account has write permissions to SomeOtherFolder folder, then the file will be saved out of strGalleryPath path.
So way you should check input data which come to you from client side. If albid should be an integer value, then you can check it with this easy code:
>>>>>>>>> Server.MapPath(strGalleryPath & CInt(Request.Form("albid")) & "\" & strNewFileName) <<<<<<<<<
If it is not integer, then server error will be raised. Sure it is better to check albid value once and add appropriate error handling.
Best regards, Fedor Skvortsov
|
|
Rank: Member Groups: Member
Joined: 6/14/2005 Posts: 5 Points: 0
|
Hi there thanks for the Help, I will take read through what you have you said.
The Form albid is a hidden form so the user will have a hard time to pass another value to it, but I take your point.
Thanks
Jason
|
|
 Rank: Advanced Member Groups: Member
Joined: 8/3/2003 Posts: 996 Points: 1
|
Hello Jason, What is the value of UploadThumbnail2FitMode property in your code? It equals to "Off" by default, so Image Uploader does not send the second thumbnail to the server in this way. You can read about it here.
Sincerely yours, Alex Makhov
|
|
Rank: Member Groups: Member
Joined: 6/14/2005 Posts: 5 Points: 0
|
Hi all,
@ Alex, thanks alot this got it woking for me. I actually figured this out yesterday, after much reading :'( .
All is good now
Great product by the way
Jason
|
|
 Rank: Advanced Member Groups: Member
Joined: 8/3/2003 Posts: 996 Points: 1
|
Glad to help you :D
Sincerely yours, Alex Makhov
|
|
|
Guest |