Link to home
Start Free TrialLog in
Avatar of N2012
N2012

asked on

FileUp - Classic ASP

I must be overlooking something very simple.

I'm using FileUp and need to modify script to allow saving to an absolute path. I cannot use a relative path (../), it must be absolute.

The code below doesn't cut it because it points to a path within the application path.

Any help is much appreciated!!!!

<%
'-----------------------------------------------------------------------
'--- FileUp Simple Upload Sample
'--- 
'--- This sample demonstrates how to perform a single file upload
'--- with FileUp

'--- This is the ASP form-response script that uses FileUp to receive and
'--- process the upload submitted from form.asp

'--- Copyright (c) 2003 SoftArtisans, Inc.
'--- Mail: info@softartisans.com   http://www.softartisans.com
'-----------------------------------------------------------------------

	'--- Declarations
	Dim oFileUp

	'--- Instantiate the FileUp object
	Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")

	'--- Set the Path property to the location you wish to
	'--- temporarily cache the incoming file before saving
	'--- Note: This property must be set immediately after
	'--- instantiating the FileUp object
	oFileUp.Path = Server.MapPath(Application("vroot") & "/temp")

	'--- Check to be sure there was a file selected in the form
	'--- If so, continue processing
	If IsObject(oFileUp.Form("myFile")) Then
		If Not oFileUp.Form("myFile").IsEmpty Then
		
			'--- Save the file
			'--- Note: The Save() method saves the file
			'--- with its original name to the directory
			'--- you set as the Path property.
			'--- To save a file to a different location
			'--- or with a different name, use the SaveAs() method
			'--- instead of Save()
			On Error Resume Next
				oFileUp.Form("myFile").Save
				If Err.Number <> 0 Then
					Response.Write "<B>An error occurred while saving the file</B><BR>" & _
									Err.Description & " (" & Err.Source & ")"
					Response.End
				End If
			On Error Goto 0

			'--- Display information about the saved file
			Response.Write "<H3>FileUp Saved the File Successfully</H3>"
			Response.Write "<DL>"
			
			'--- ServerName is the full path of the file as it was saved on the server
			Response.Write "<DT><B>Path on server</B></DT><DD>" & oFileUp.Form("myFile").ServerName & "</DD>"
			'--- UserFilename is the full path of the file as it was sent from the client
			Response.Write "<DT><B>Path on client</B></DT><DD>" & oFileUp.Form("myFile").UserFilename & "</DD>"
			'--- ShortFileName is just the Userfilename without the path
			Response.Write "<DT><B>Short filename</B></DT><DD>" & oFileUp.Form("myFile").ShortFilename & "</DD>"
			'--- TotalBytes is the byte size of the file
			Response.Write "<DT><B>Byte size</B></DT><DD>" & oFileUp.Form("myFile").TotalBytes & "</DD>"
			'--- ContentType is the mime type of the file. Eg, "application/msword"
			Response.Write "<DT><B>Content type</B></DT><DD>" & oFileUp.Form("myFile").ContentType & "</DD>"
			'--- CheckSum is the MD5 hash of the file that can be used to check file integrity
			Response.Write "<DT><B>CheckSum</B></DT><DD>" & oFileUp.Form("myFile").CheckSum & "</DD>"
			Response.Write "</DL>"
			
		Else
			Response.Write "There was no file submitted in the form field."
		End If
	Else
		Response.Write "The referenced field does not exist or is not of type=""file"""
	End If

	'--- Dereference FileUp
	Set oFileUp = Nothing
%>

Open in new window

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

oFileUp.Path = Server.MapPath(Application("vroot") & "/temp")

can you debug what's the output of Server.MapPath(Application("vroot") & "/temp") ?

Server.MapPath should return a physical path instead of relative path in this case.
Avatar of N2012
N2012

ASKER

It points to the website path, /temp folder. This script uploads a file, then I can just pick it up from the website anonymously (/temp/fileuploaded.zip)

I want to point to a different drive/directory than the one the site is on, which is why I need this updated to absolute path.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of N2012

ASKER

gotta be, I was putting the full path in quotes within the () duh....
will check and let you know
Avatar of N2012

ASKER

THANKS!!!
Probably the simplest answer you had to give today.  :)