Solved

Find the physical path of file

Posted on 2004-08-04
10
573 Views
Last Modified: 2008-03-06
Hi

I've played around with code like this:

<?php
$conn_id = ftp_connect("xxx.com");
$login_result = ftp_login($conn_id, "user", "passw");
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
die;
} else {
echo "Connected";
}
$contents = ftp_nlist($conn_id, ".");
echo implode($contents,"/");
ftp_quit($conn_id);
?>

This code shows the files in a ftp-directory but I would also like to show the physical path to the individual files. Is this possible? Points to those who integrate the necessary code in the above.

Thanx,

Soren
0
Comment
Question by:speder
  • 5
  • 3
  • 2
10 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 70 total points
ID: 11723551
I don't understand exactly what you want but I guess it is something like this (sorry, I can't test the script right now)

<?php
$conn_id = ftp_connect("xxx.com");
$login_result = ftp_login($conn_id, "user", "passw");
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
die;
} else {
echo "Connected";
}
$currentdir = ftp_pwd();
$contents = ftp_nlist($conn_id, ".");
$all = implode($contents,":");
$all = str_replace(":",":$currentdir",$all);
echo ($all);
ftp_quit($conn_id);
?>

0
 

Author Comment

by:speder
ID: 11723644
I think this only returns the directory name. I would like it to return the physical path to the individual files. Like the asp-function Server.MapPath.
0
 
LVL 3

Assisted Solution

by:thecode101
thecode101 earned 30 total points
ID: 11727078
If the ftp user is set up to log in to the root directory on the server then the ftp_pwd() will return the entire phsyical directory of the file and Jaime's code should work.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:speder
ID: 11727396
I've probably used the wrong terms, but by physical path I mean for example "d:\inetpub\wwwroot\index.htm". If I have a ftp-login that starts in wwwroot, the ftp_pwd() would not return the whole path, or am I wrong?

0
 
LVL 3

Expert Comment

by:thecode101
ID: 11727455
Correct if your ftp user starts in wwwroot, ftp_pwd() will not return the whole path, but if you set the ftp login to start in d:\ it will return the whole path.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11727456
ftp_pwd does return physical directory, by example:

/var/apache/yourassigneddir/
0
 

Author Comment

by:speder
ID: 11727513
Ok - so if I start in wwwroot is there a way to get the whole physical path anyway (the whole d:\inetpub\wwwroot)?

If not, I guess I would have to upload a asp-script to the server (this only targets iis-servers) and then afterwards read the script and see what it returns.
0
 
LVL 3

Expert Comment

by:thecode101
ID: 11727699
If the php command ftp_raw is working on the server you could try something like
ftp_raw ($conn_id,'pwd')
But I have not tested this because the function does not work with my version of php.

http://us2.php.net/manual/en/function.ftp-raw.php
0
 

Author Comment

by:speder
ID: 11754238
This piece of code return the correct top folder list og files and folders for both linux- and windows server. I don't know if this can help:

<?php
$conn_id = ftp_connect("ftp.xxx.com");
$login_result = ftp_login($conn_id, "yyy", "zzz");
if ((!$conn_id) || (!$login_result)) {
echo "Ftp connection has failed!";
die;
} else {
echo "Connected";
}
$contents = ftp_nlist($conn_id, ".");
echo implode($contents,"/");
ftp_quit($conn_id);
?>
0
 

Author Comment

by:speder
ID: 11754290
ups - wrong place.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question