+ Reply to Thread
Results 1 to 4 of 4

Thread: Check if file already exist (using freeaspupload)

  1. #1
    Barn Regular PhloooooIsFlo is on a distinguished road PhloooooIsFlo's Avatar
    Join Date
    Jul 2008
    Location
    Indonesia
    Posts
    64
    Rep Power
    3

    Check if file already exist (using freeaspupload)

    Hi All,

    Need help again here
    I'm using freeaspupload, and i modified a bit on renaming the file i've uploaded. The problem is if i upload the same filename, it gives me error like this :
    Microsoft VBScript runtime (0x800A003A)
    File already exists
    /web/ltl2009hostv4ok/www/corporate/upload.asp, line 181

    I tried to put this code :
    Code:
     for each fileKey in Upload.UploadedFiles.keys
                'SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B)"
    			strFileType = Left(Upload.UploadedFiles(fileKey).ContentType,5)
                if strFileType = "image" or strFileType="appli" Then
    				
    					'SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
    					strFileName=Upload.UploadedFiles(fileKey).FileName
    					if inStr(strFileName,".jpg") or inStr(strFileName,".doc") or inStr(strFileName,".pdf") or inStr(strFileName,".docx") then
    						if not Upload.UploadedFiles(fileKey).Length>1000000 then
    							directory=uploadsDirVar & Upload.UploadedFiles(fileKey).FileName
    							'=====modified - start rename file=====
    							set fso = CreateObject("Scripting.FileSystemObject") 
    							set file = fso.GetFile(directory) 
    							file.name = session.Contents("ID") &"-"& strFileName 
    							'=====start check if file exist====='
    							Dim objFSO, strFileNameUp
    							strFileNameUp = directory 
    							Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    							If objFSO.FileExists (strFileNameUp) Then 
    								DelFile = DelFile & strFileNameUp & ","
    								SaveFiles = "File is exist" 
    							Else
    								SaveFiles = "File does not exist"
    							End If
                                                           '=====endcheck if file exist====='
     
    							myImageArray(counter) = file.name 
    							counter = counter + 1
    							set file = nothing 
    							set fso = nothing
    							'=====modified - end rename file======
    						else
    						   DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
    						   SaveFiles = "File is too large, please attach smaller size"
    						end if
    					else
    					   DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
    					   SaveFiles = "Invalid File Name, please attach the correct one"
    					end if
    			else
                    DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
    				SaveFiles = "Invalid File Type, please attach the correct one"
                end if      
            next
    
    Does anyone can help? thank you in advance =)

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    Could you highlight line 181?

  3. #3
    Barn Regular PhloooooIsFlo is on a distinguished road PhloooooIsFlo's Avatar
    Join Date
    Jul 2008
    Location
    Indonesia
    Posts
    64
    Rep Power
    3

    Hi RR, sorry i just sort out the problem ^^

    the previous error message is on : file.name = session.Contents("ID") &"-"& strFileName

    this code below works :
    Code:
    for each fileKey in Upload.UploadedFiles.keys
                'SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B)"
    			strFileType = Left(Upload.UploadedFiles(fileKey).ContentType,5)
                if strFileType = "image" or strFileType="appli" Then
    				
    					'SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
    					strFileName=Upload.UploadedFiles(fileKey).FileName
    					if inStr(strFileName,".jpg") or inStr(strFileName,".doc") or inStr(strFileName,".pdf") or inStr(strFileName,".docx") then
    						if not Upload.UploadedFiles(fileKey).Length>1000000 then
    							directory=uploadsDirVar & Upload.UploadedFiles(fileKey).FileName
    							'=====start modified  rename file=====
    							set fso = CreateObject("Scripting.FileSystemObject") 
    							set file = fso.GetFile(directory) 
    							dim cekFile
    							
    							cekFile=uploadsDirVar & session.Contents("ID") &"-"& Upload.UploadedFiles(fileKey).FileName
    							 
                                                           '=======start check if file exist========
    
    							if fso.FileExists(cekFile)=true then
    							  response.write(cekFile&"already exists!")
    							  DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
    							  SaveFiles = "File is already exist"
    							else
    							  response.write(cekFile&"does not exist!")
    							  file.name = session.Contents("ID") &"-"& strFileName
    							end if
    
    							   '=======end check if file exist========
    
    							myImageArray(counter) = file.name 
    							counter = counter + 1
    							set file = nothing 
    							set fso = nothing
    							'=====end modified rename file======
    						else
    						   DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
    						   SaveFiles = "File is too large, please attach smaller size"
    						end if
    					else
    					   DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
    					   SaveFiles = "Invalid File Name, please attach the correct one"
    					end if
    			else
                    DelFile = DelFile & Upload.UploadedFiles(fileKey).FileName & ","
    				SaveFiles = "Invalid File Type, please attach the correct one"
                end if      
            next
    
    Sorry to waste your time here, RR ^^

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    No problem. Glad you got it sorted...

+ Reply to Thread

Similar Threads

  1. ServiceModel does not Exist in namespace System
    By richyrich in forum .Net Development
    Replies: 5
    Last Post: October 17th, 2009, 02:57 PM
  2. Check Book
    By alansidman in forum Access Database Samples
    Replies: 0
    Last Post: June 7th, 2009, 04:40 PM
  3. Check box pop up information??
    By dtz in forum JavaScript Programming
    Replies: 4
    Last Post: May 1st, 2009, 07:21 AM
  4. How do I check the tag of a child?
    By bryceowen in forum JavaScript Programming
    Replies: 4
    Last Post: February 19th, 2009, 02:01 PM
  5. Check if result set is empty
    By noFriends in forum PHP Development
    Replies: 6
    Last Post: June 27th, 2008, 08:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO