简体   繁体   English

尝试使用php连接到本地服务器(ftp_connect)

[英]trying to connect to local server using php (ftp_connect)

I have a server set up with Apache2 on linux and I'm trying to upload a file to that server. 我在Linux上使用Apache2设置了服务器,并且正在尝试将文件上传到该服务器。

I am using: 我在用:

$conn = ftp_connect("localhost") or die("Server connection failed.");

to achieve this, though it is not working. 为达到这一目的,尽管它不起作用。

I have tried a "wget" command to the same server though that failed also with this response: 我曾尝试对同一台服务器执行“ wget”命令,但此响应也失败了:

Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:21... failed: Connection refused.

Does anybody know how to allow my server to be used in the ftp_connect php command? 有人知道如何在ftp_connect php命令中使用我的服务器吗?

Thank you very much guys. 非常感谢你们。

As mentioned in the comment by Maerlyn, Apache is an HTTP server. 如Maerlyn的评论中所述,Apache是​​HTTP服务器。 That means it can only communicate via the HTTP protocol. 这意味着它只能通过HTTP协议进行通信。

You are attempting to connect to an FTP-server, that's a completely different thing(!). 您正在尝试连接到FTP服务器,那是完全不同的事情(!)。

However, what I think you want to do is not connect to an FTP server and upload files via that; 但是,我认为您要做的是不连接到FTP服务器并通过该服务器上传文件。 rather what you want to do is use an HTTP POST (or PUT) request to upload a file to the server. 而是要使用HTTP POST(或PUT)请求将文件上传到服务器。

The way to do that is to have an HTML form with a method="post" , containing an <input type="file"> element. 这样做的方法是使HTML表单带有method="post" ,其中包含<input type="file">元素。 When this is submitted, the PHP page will receive the file in the $_FILES superglobal, which you can then move to wherever you want it using functions such as move_uploaded_file() . 提交后,PHP页面将在$_FILES超全局文件中接收该文件,然后您可以使用诸如move_uploaded_file()函数将其移至所需的任何位置。

For a more in-depth explenation, please see the PHP manual 有关更深入的说明,请参见PHP手册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM