Avatar billede kometen79 Nybegynder
12. april 2004 - 03:48 Der er 1 løsning

Hjælp til ASP upload

Hvordan gemmer jeg filerne i 2 mapper?

Set objUpload = Server.CreateObject("Persits.Upload.1")

            With objUpload


                'make sure files arn't over written
                .OverwriteFiles = False

                'We need to save the file before we can find out anything about it
                '** Save virtual is used as saving to memory is often disabled by the web host **
                .SaveVirtual strFileUploadPath

                'Get the file name
                strNewFileName = .Files(1).ExtractFileName

                'Replace spaces with underscores
                strNewFileName = Replace(strNewFileName, " ", "_", 1, -1, 1)

                'Remove brackets that aspUpload may put in when renaming a file
                strNewFileName = Replace(strNewFileName, "(", "", 1, -1, 1)
                strNewFileName = Replace(strNewFileName, ")", "", 1, -1, 1)

                'Check the file size is not above the max allowed size, this is done using a function not the compoent to stop an exception error
                lngErrorFileSize = fileSize(.Files(1).Size, intMaxFileSize)

                'Loop through all the allowed extensions and see if the file has one
                blnExtensionOK = fileExtension(strNewFileName, saryFileUploadTypes)

                'If the file is OK save it to disk
                If lngErrorFileSize = 0 AND blnExtensionOK = True Then

                    '** AspUpload does have a function to stop files form being over written but this can allow the forum open to malicious code **
                    '** so instead if the file exists create an acceptable new name for the file **
                    'Check to make sure the file does not already exist
                    Do While .FileExists(Server.MapPath(strFileUploadPath) & "\" & strNewFileName)

                        'Create a new file name for the file if it already exsist
                        strNewFileName = hexValue(3) & "_" & strNewFileName
                    Loop
                   

                    'Save the file to disk with new file name
                    '** Copy virtual is used as save as is often disabled by the web host **
                    .Files(1).CopyVirtual strFileUploadPath & "/" & strNewFileName

                    'As a new copy of the file is saved we need to get rid of the old copy
                    .Files(1).Delete

                    'Pass the filename back
                    fileUpload = strNewFileName


                'Else if it is not OK delete the uploaded file
                Else
                    .Files(1).Delete

                End If

            End With

            'Clean up
            Set objUpload = Nothing
Avatar billede kometen79 Nybegynder
16. april 2004 - 08:09 #1
Lukker
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester