Current location: Hot Scripts Forums » Programming Languages » ASP » Changing filename during upload


Changing filename during upload

Reply
  #1 (permalink)  
Old 05-12-04, 02:27 PM
dasphatman dasphatman is offline
New Member
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Changing filename during upload

Is there anyway that you can change the name on a file during upload, ex. i have a imagefile called "summer.gif" and i want to make the filename "image1.jpg"

I'm using a script like this.

<%
Dim oUpload
Dim oFile
Dim sFileName
Dim oFSO
Dim sPath
Dim sNewData
Dim nLength
Dim bytBinaryData


Const nForReading = 1
Const nForWriting = 2
Const nForAppending = 8

' grab the uploaded file data
Set oUpload = New clsUpload
Set oFile = oUpload("File1")

' parse the file name
sFileName = ""
If Not InStr(sFileName, "\") = 0 Then
sFileName = Mid(sFileName, InStrRev(sFileName, "\") + 1)
End If

' Convert the binary data to Ascii
bytBinaryData = oFile.BinaryData
nLength = LenB(bytBinaryData)
For nIndex = 1 To nLength
sNewData = sNewData & Chr(AscB(MidB(bytBinaryData, nIndex, 1)))
Next

' Save the file to the file system
sPath = Server.MapPath(".\Uploads") & "\"
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
oFSO.OpenTextFile(sPath & sFileName, nForWriting, True).Write sNewData
Set oFSO = Nothing

Set oFile = Nothing
Set oUpload = Nothing
%>

Cant seem to find a way.

//jesper
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-24-04, 09:55 PM
Mikeirv Mikeirv is offline
Newbie Coder
 
Join Date: May 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by dasphatman
Is there anyway that you can change the name on a file during upload, ex. i have a imagefile called "summer.gif" and i want to make the filename "image1.jpg"

I'm using a script like this.

<%
Dim oUpload
Dim oFile
Dim sFileName
Dim oFSO
Dim sPath
Dim sNewData
Dim nLength
Dim bytBinaryData


Const nForReading = 1
Const nForWriting = 2
Const nForAppending = 8

' grab the uploaded file data
Set oUpload = New clsUpload
Set oFile = oUpload("File1")

' parse the file name
sFileName = ""
If Not InStr(sFileName, "\") = 0 Then
sFileName = Mid(sFileName, InStrRev(sFileName, "\") + 1)
End If

' Convert the binary data to Ascii
bytBinaryData = oFile.BinaryData
nLength = LenB(bytBinaryData)
For nIndex = 1 To nLength
sNewData = sNewData & Chr(AscB(MidB(bytBinaryData, nIndex, 1)))
Next

' Save the file to the file system
sPath = Server.MapPath(".\Uploads") & "\"
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
oFSO.OpenTextFile(sPath & sFileName, nForWriting, True).Write sNewData
Set oFSO = Nothing

Set oFile = Nothing
Set oUpload = Nothing
%>

Cant seem to find a way.

//jesper
Try this:

'// Change this line

oFSO.OpenTextFile(sPath & "image1.jpg", nForWriting, True).Write sNewData
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Stuck on imagejpeg whilst trying to upload BLOB to MySQL! zcosgrove PHP 5 06-30-10 12:03 PM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 10:54 PM
will pay. php script needed. upload, resize, & email jamjammo Script Requests 4 02-29-04 09:30 PM
Auto-rename when upload? dragge PHP 1 01-15-04 04:03 AM
Help with my upload script TheMetsAreBad PHP 2 12-04-03 07:10 PM


All times are GMT -5. The time now is 07:09 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.