PHP : ftp_alloc() function
Description
The ftp_alloc() function is used to allocate space for a file to be uploaded to the FTP server.
Version
(PHP 5)
Syntax
ftp_alloc(ftp_stream, file_size, server_res)
Parameters
| Name | Description | Required / Optional |
Type |
|---|---|---|---|
| ftp_stream | The link identifier of the FTP connection. | Required | Resource |
| file_size | The number of bytes to allocate. | Required | integer |
| server_res | A variable to store server response (textual representation). | Optional | string |
Return value
TRUE on success or FALSE on failure.
Value Type : Boolean.
Example :
<?php
$file = "d:\test.txt";
/* connect to the server */
$conn_id = ftp_connect('192.168.0.2');
$login_result = ftp_login($conn_id, 'abc123', 'abc123');
if (ftp_alloc($conn_id, filesize($file), $result)) {
echo "Space successfully allocated on server. Sending $file.\n";
ftp_put($conn_id, 'D:/ds', $file, FTP_BINARY);
} else {
echo "Unable to allocate space on server. Server said: $result\n";
}
ftp_close($conn_id);
?>
See also

