我正在尝试在处理 PHP 表单时创建一个新的 ftp 帐户。如果我在浏览器的地址栏中输入此地址:
http://cpanel_username:cpanel_password@$mydomain.com:2082/json-api/cpanel?cpanel_jsonapi_version=2&cpanel_jsonapi_module=Ftp&cpanel_jsonapi_func=addftp&user=ftp_username&pass=ftp_password&homedir=/the/users/homefolder"a=0
... json 格式的结果显示在屏幕上,并按指定创建一个 ftp 帐户。但是,当我在 PHP 文件中使用它时,我无法让它工作!这是我所拥有的:
$user = "cpanel_username";
$pass = "cpanel_password";
$domain = "mydomain.com";
$fuser = "ftp_username";
$fpass = "ftp_password";
$fhomedir = "/the/users/homefolder";
$url = "http://$user:$pass@$domain:2082/json-api/cpanel?cpanel_jsonapi_version=2&cpanel_jsonapi_module=Ftp&cpanel_jsonapi_func=addftp&user=$fuser&pass=$fpass&homedir=$fhomedir"a=0";
file_get_contents($url);
我也尝试使用 CURL:
function new_get_file_contents($url) {
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
return $file_contents;
}
new_get_file_contents($url);
任何想法为什么我不能让它工作?