Jump to content

--HELP!!!---


z20let

Recommended Posts

Me and my IT Officer are in need of some help with the following:

We are trying to open a directory -> read files in the directory -> when the files are clicked on they can open up each file...

 

However we are having no such luck :(

 

Here is the code

 

<?php
$path = 'C:/Inetpub/wwwroot/intranet/';
$dh = opendir($path);
$i=1;
while (($file = readdir ($dh)) !== false){
if($file != "." && $file != "..") {
		if (substr($file, -4, -3) =="."){
		echo $i.". <a href='$path.$file'> $file </a><br />";			
		}else{
	echo $i.". <a href='$path.$file'> $file </a><br />";		
		}
	$i++;
}
}
closedir($dh);
?>
<a href="C:/Inetpub/wwwroot/intranet/test.txt">test</a>

 

The directory is shown, however clicking on the links does nothing :( Help!

 

(edited by kenrbnsn to add


tags)

Link to comment
Share on other sites

Thanks Ken for editing my post (didn't know you could put the code into code brackets on here)

 

We are testing opening files both on the local machine (within the domain) and external files (not on the domain)

 

The domain at the moment is wwwroot (yep you've guessed it - we are using IIS)

 

I looked at the source Scott and it is pointing to the actual file (c://wwwroot/intranet/test.txt) rather than looking at the localhost which is what we want to happen!

Link to comment
Share on other sites

Guest Xanza

Then use variables

 

<?php
$path = "C:/Inetpub/wwwroot/intranet/";
$final_file = $_SERVER['SCRIPT_FILENAME'];
$dh = opendir($path);
$i=1;
while(($file = readdir($dh)) !== false){
if($file != "." && $file != "..") {
		if(substr($file, -4, -3) == "."){
		echo $i.". <a href='$path.$file'> $file </a><br />";			
		} else {
	echo $i.". <a href='$path.$file'> $file </a><br />";		
		}
	$i++;
}
}
closedir($dh);

if(!$_SERVER['REMOTE_ADDR'] == "127.0.0.1"){
   echo '<a href="$final_file">test</a>';
} else {
   echo '<a href="file://$final_file">test</a>';
}

?>

 

That could work, I've never worked with a windows based server before... But either way that should point you in the right direction.

Link to comment
Share on other sites

Then use variables

 

<?php
$path = "C:/Inetpub/wwwroot/intranet/";
$final_file = $_SERVER['SCRIPT_FILENAME'];
$dh = opendir($path);
$i=1;
while(($file = readdir($dh)) !== false){
if($file != "." && $file != "..") {
		if(substr($file, -4, -3) == "."){
		echo $i.". <a href='$path.$file'> $file </a><br />";			
		} else {
	echo $i.". <a href='$path.$file'> $file </a><br />";		
		}
	$i++;
}
}
closedir($dh);

if(!$_SERVER['REMOTE_ADDR'] == "127.0.0.1"){
   echo '<a href="$final_file">test</a>';
} else {
   echo '<a href="file://$final_file">test</a>';
}

?>

 

That could work, I've never worked with a windows based server before... But either way that should point you in the right direction.

 

Sorry mate that doesn't work - the IT Officer said that we aren't trying to check other servers IP Addresses we are simply trying to read/write files on a directory...

 

The user will try and access a file which maybe in c://documents/test.doc instead of accessing it from the normal location c:\inetpub\wwwroot\intranet\test.doc 

Link to comment
Share on other sites

Guest Xanza
Sorry mate that doesn't work - the IT Officer said that we aren't trying to check other servers IP Addresses we are simply trying to read/write files on a directory...

 

 

You're going to have to read what kenrbnsn said, cause I really don't feel like explaining it to your IT Officer. ;)

 

And yes, I know that the directories might change, which is exactly why I incorporated "$final_file = $_SERVER['SCRIPT_FILENAME'];", which you could amend to your liking.

 

Also, tell your IT Officer that searching for the IP is essential, otherwise how do you expect to dynamically incorporate "file://" which is what local users need (if your running a centralized windows server (intranet)) to access the url's.

 

The purpose of this help section is for input and small help, no one is going to remake your script for you, because we really still can't tell exactly what you're doing, and even if you fully and completely explained it, it would still be difficult to create what you need - simply because we don't have the intranet right infront-of-us to be able to debug.

 

My final advise is to just run with what you have, and change what I added to meet your needs... But either way, your going to have to use a combination of them sooner or later. :P

 

also, what I just saw (mybad):

 

if(!$_SERVER['REMOTE_ADDR'] == "127.0.0.1"){

 

on your local intranet the address (127.0.0.1) is going to change, you'll need to configure it to suit your needs.

Link to comment
Share on other sites

Ok,

 

Seems like a mis-understanding on my part so I apologise for this, I fully understand that people can only give/make suggestions on forums and for that I am also grateful...

 

Here might be a better example...

All users are on Server A

The intranet is on Server B

 

Server A is very restrictive (to which we are not able to fully modify because it's managed by an external IT contractor)

 

Server B is our own server which we are running the web server from here...

 

When a user logs onto Server A all that they are required to do is click onto the internet -> this should then take them into the intranet (from here there windows logon name will be displayed as well as many directories being shown to them)

 

We are simply trying to test to see if a user is able to read/write files which could either be on Server A, B or a different server entirely....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.