w3resource

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

PHP Function Reference

Previous: var_export
Next: ftp_cdup



PHP: Tips of the Day

PHP: PHP Constants Containing Arrays?

NOTE: while this is the accepted answer, it's worth noting that in PHP 5.6+ you can have const arrays

You can also serialize your array and then put it into the constant:

# define constant, serialize array
define ("FRUITS", serialize (array ("apple", "cherry", "banana")));

# use it
$my_fruits = unserialize (FRUITS);

Ref : https://bit.ly/2EcIer8