Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Mixing ASP and PHP


  • Please log in to reply

#1
Immortalarena

Immortalarena

    Member

  • Member
  • PipPipPip
  • 211 posts
I am adding a little script to my page to allow me to upload a file, overwriting the old one. The site is hosted in an ASP environment, so I wanted to keep it that way if possible.

The problem is I don't know the "Path" to save the file. I have a PHP script that works, but I need to secure the page, that way only a logged in user can get to the page. So I need help in 1 of two ways. I either need the PHP page to check the session set by ASP, or I need to get a method of an ASP upload script to upload to ../_private/ directory. It will only be 1 file being uploaded at a time. The PHP code I have right now is as follows:

<?php
// Where the file is going to be placed 
$target_path = "../_private/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$_FILES['uploadedfile']['tmp_name'];  

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
	echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
	" has been uploaded";
} else{
	echo "There was an error uploading the file, please try again!";
}

?>

The ASP code for checking authenticity is as follows:
<%Response.Buffer=TRUE%>
<%IF session("admin") = FALSE THEN Response.Redirect "../login.asp"%>


So Basically I need to merge the two into 1 page. Any ideas or Help is greatly appreciated! Thanks,
:)
  • 0

Advertisements


#2
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
Hello,

Since you're using ASP already, can't you just use the Server.MapPath function to get the path?
  • 0

#3
Immortalarena

Immortalarena

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 211 posts
I'll have to try that! Thanks,

-Matt
  • 0

#4
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
:) Let me know how it works out.
  • 0

#5
Immortalarena

Immortalarena

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 211 posts
I will admit I am still having trouble, I can't seem to find an ASP Script that is working for me. Any ideas? I tried to post the mappath into my code, and all I got was an error, but I'm sure I just found a bad upload script in ASP. Thanks!

This upload is going to be in a secure zone to simply upload 1 access database, because we need to update this database remotely. I was just hoping I would not have to log into the ftp every time I needed to upload this file. So I don't need anything too fancy. Thanks,

Matt

P.S. I'm also a bit under the weather with a cold, so if I don't get back right away, I apologize.
  • 0

#6
Ax238

Ax238

    Tech Staff

  • Technician
  • 1,323 posts
I think I may have misunderstood your original intention. Server.MapPath works well in obtaining the server-side path of a resource. You are dealing with an attempt to get the path from the client-side. A few stipulations with ASP:
The form needs to have enctype="multipart/form-data"

Processing the upload with ASP requires you to process a byte array, which can get tricky. There are scripts that can do this for you, such as the following:
ASP 101 - Pure ASP File Upload

Personally, I think you'd be much better off updating your database from the command line, using a batch file and the ftp command. I can help you if you need, but here's a pretty good example:
FTP Code Example: Automatically update your website with an FTP batch file

Much easier, and less work for you, especially if you use a scheduled task to run it!
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP