为文件分配空间并将文件上传到FTP服务器:
<?php
// connect and login to FTP server
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$file = "/test/myfile";
// allocate space
if (ftp_alloc($ftp_conn, filesize($file), $result))
{
echo "Space allocated on server. Sending $file.";
ftp_put($ftp_conn, "/files/myfile", $file, FTP_BINARY);
}
else
{
echo "Error! Server said: $result";
}
// close connection
ftp_close($ftp_conn);
?>
ftp_alloc() 函数为要上传到 FTP 服务器的文件分配空间。
笔记:许多FTP服务器不支持该命令!
ftp_alloc(
ftp_conn, filesize, result);
Parameter | Description |
---|---|
ftp_conn | Required. Specifies the FTP connection to use |
filesize | Required. Specifies the number of bytes to allocate |
result | Optional. Specifies a variable to store the server response in |
返回值: | TRUE 成功,FALSE 失败 |
---|---|
PHP 版本: | 5+ |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!