问题
Suddenly when I'm doing this on my server:
<?php
$connection = ftp_connect("ftpserver"); // connect to server
print($connection);print("test");die();
?>
It does not return a Resource id #
.
It happens only on a particular server, if I try the same code on another server it will return:
Resource id #2test
Is it a server configuration? Nothing changed on that server recently. It prints just "test", no null or something else. I've tried multiple ftp servers to make sure that the server IP is not banned.
Tried function_exists('ftp_connect')
and it is.
Update: check /var/log/syslog to see if it is blocked by firewall.
回答1:
The ftp_connect function returns false
, if the connection fails.
Printing false
yields nothing (the false
converts to an empty string).
Use the var_dump($connection)
to verify.
You will most likely get:
bool(false)
Meaning that you cannot connect to the "ftpserver".
The ftp_connect
should issue a warning with details about the connection problem.
来源:https://stackoverflow.com/questions/36574741/ftp-connect-does-not-return-a-resource-id