如何获取上传到 FTP 服务器的文件的 HTTP URL
以下是我将文件上传到其他服务器的代码,
Below is my code to upload file to other server ,
$ftp_server="host";
$ftp_user_name="";
$ftp_user_pass="";
$file = "referesh.php";//tobe uploaded
$name = "diff_adtaggeneration";
$remote_file = $name."/referesh.php";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$res = ftp_rawlist($conn_id, $name);
//print_r($_SERVER);exit;
if(count($res) > 0)
{
ftp_put($conn_id, $remote_file, $file, FTP_ASCII);
}
else
{
ftp_mkdir($conn_id, $name);
ftp_put($conn_id, $remote_file, $file, FTP_ASCII);
}
ftp_close($conn_id);
上面的代码完美运行,文件成功上传到其他服务器,新文件夹名称'diff_adtaggeneration'将在目录的根目录中创建,文件上传到该文件夹,我需要获取上传的文件路径..!我使用 print_r($_SERVER)
,我知道这仅显示当前服务器详细信息,但如何获取上传服务器(其他服务器)的根目录完整文件路径.任何帮助表示赞赏...
above code works perfectly, the file succesfully uploaded to other server, the new folder name 'diff_adtaggeneration' will create in root of the directory and file uploaded in that folder, and I need to get the uploaded file path ..! I use print_r($_SERVER)
, I know this shows only current server details, but how to get the root directory full file path of uploaded server(other server). Any help appreciated...
推荐答案
没有神奇的方法可以找到上传到 FTP 服务器的文件的 HTTP URL,恰好与 HTTP 服务器共享一个文件存储.
There's no magical way to find out an HTTP URL of the file uploaded to an FTP server, that happens to share a file storage with the HTTP server.
p>
这是 FTP 和 HTTP 服务器的配置问题;它们如何将虚拟 HTTP 和 FTP 路径映射到实际的文件系统路径.
It's a matter of configuration of both the FTP and HTTP servers; how do they map virtual HTTP and FTP paths to and from an actual file system paths.
映射可以是完全虚拟的和不确定的.
The mapping can be completely virtual and undeterministic.
话虽如此,大多数网络托管在 FTP 和 HTTP 上都有一定的根,从那里映射是确定性的.
Having that said, most web hostings have some root both on FTP and HTTP, from where the mapping is deteministics.
如果您连接到 FTP,您通常会进入 HTTP 主机的根文件夹,或者直接位于其下方(会有一个子文件夹,例如 httpdocs
或 www
映射到 HTTP 根目录).
If you connect to the FTP, you usually land in the root folder of the HTTP hosting, or immediately below it (there would be a subfolder like httpdocs
or www
that maps to the HTTP root).
如果 FTP 帐户是 chrooted,根文件夹将是 /
(或 /httpdocs
等).
If the FTP account is chrooted, the root folder will be /
(or /httpdocs
, etc).
如果您有自己的域 (www.example.com
),那么像 /index.html
这样的 FTP 路径会映射到 https://www.example.com/index.html
.
If you have your own domain (www.example.com
), then an FTP path like /index.html
maps to https://www.example.com/index.html
.
这是最简单的情况.它可以是一种更复杂的方式.但这是我们无法帮助您的事情.这是您的网络托管服务提供商和/或管理员的问题.
That's the most simple case. It can be a way more complicated. But that's something we cannot help you with. That's a question for your web hosting provider and/or administrator.
相关文章