Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
JasonChandler  
#1 Posted : Monday, June 13, 2005 10:23:00 PM(UTC)
JasonChandler

Rank: Member

Groups: Member
Joined: 6/13/2005(UTC)
Posts: 5

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
        'Get total number of uploaded files 
        Dim intFileCount As Integer = CInt(Request.Form("FileCount"))

        Dim I As Integer, SourceFile As HttpPostedFile, ThumbnailFile As HttpPostedFile
        'We iterate through the uploaded files and save them and appropriate data
        For I = 1 To intFileCount
            'Get source image and save it to disk
            SourceFile = Request.Files("SourceFile_" & I)
            Dim strFileName As String = Path.GetFileName(SourceFile.FileName)
            'Check whether file with such name already exists and if so,
            'construct safe filename name (to avoid collision)
            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))

            'Get first thumbnail 
            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

          'Get Second thumbnail 
            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


            'Save description to the database
            'ParameterName.Value = strFileName
            'ParameterWidth.Value = CInt(Request.Form("Width_" & I))
            'ParameterHeight.Value = CInt(Request.Form("Height_" & I))
            'ParameterDescription.Value = Request.Form("Description_" & I)
            'MyCommand.ExecuteNonQuery()

            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

==================

Edited by user Sunday, December 23, 2007 5:59:46 PM(UTC)  | Reason: Not specified

Fedor  
#2 Posted : Monday, June 13, 2005 11:01:00 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
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))

'Get first thumbnail
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

'Get Second thumbnail
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))

'Get first thumbnail
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

'Get Second thumbnail
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 

<<<<<<<<<<<<<

Edited by user Wednesday, October 29, 2008 3:00:07 PM(UTC)  | Reason: Not specified

Best regards,
Fedor Skvortsov
Fedor  
#3 Posted : Monday, June 13, 2005 11:14:00 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
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
JasonChandler  
#4 Posted : Monday, June 13, 2005 11:42:00 PM(UTC)
JasonChandler

Rank: Member

Groups: Member
Joined: 6/13/2005(UTC)
Posts: 5

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
Alex Makhov  
#5 Posted : Tuesday, June 14, 2005 1:31:00 PM(UTC)
Alex Makhov

Rank: Advanced Member

Groups:
Joined: 8/3/2003(UTC)
Posts: 998

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.

Edited by user Tuesday, February 26, 2008 2:24:47 AM(UTC)  | Reason: Not specified

Sincerely yours,
Alex Makhov

UserPostedImage Follow Aurigma on Twitter!
JasonChandler  
#6 Posted : Tuesday, June 14, 2005 7:43:00 PM(UTC)
JasonChandler

Rank: Member

Groups: Member
Joined: 6/13/2005(UTC)
Posts: 5

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
Alex Makhov  
#7 Posted : Tuesday, June 14, 2005 7:59:00 PM(UTC)
Alex Makhov

Rank: Advanced Member

Groups:
Joined: 8/3/2003(UTC)
Posts: 998

Glad to help you :D
Sincerely yours,
Alex Makhov

UserPostedImage Follow Aurigma on Twitter!
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.