如何获取上传到FTP服务器的文件的HTTP URL [英] How to get HTTP URL of file uploaded to FTP server

查看:2243
本文介绍了如何获取上传到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.

这是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上都有一些根,但映射是deteministics。

Having that said, most web hostings have some root both on FTP and HTTP, from where the mapping is deteministics.

如果您连接到FTP,您通常会登陆HTTP主机的根文件夹,或者紧接在它下面(会有一个子文件夹,如 httpdocs 或映射到HTTP根目录的 www

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 ),那么像<$ c这样的FTP路径$ c> /index.html 映射到 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.

这篇关于如何获取上传到FTP服务器的文件的HTTP URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆