Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
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

How to Sort Multi-dimensional Array by Value?

Try a usort, If you are still on PHP 5.2 or earlier, you'll have to define a sorting function first:

Example:

function sortByOrder($a, $b) {
    return $a['order'] - $b['order'];
}

usort($myArray, 'sortByOrder');

Starting in PHP 5.3, you can use an anonymous function:

usort($myArray, function($a, $b) {
    return $a['order'] - $b['order'];
});

And finally with PHP 7 you can use the spaceship operator:

usort($myArray, function($a, $b) {
    return $a['order'] <=> $b['order'];
});

To extend this to multi-dimensional sorting, reference the second/third sorting elements if the first is zero - best explained below. You can also use this for sorting on sub-elements.

usort($myArray, function($a, $b) {
    $retval = $a['order'] <=> $b['order'];
    if ($retval == 0) {
        $retval = $a['suborder'] <=> $b['suborder'];
        if ($retval == 0) {
            $retval = $a['details']['subsuborder'] <=> $b['details']['subsuborder'];
        }
    }
    return $retval;
});

If you need to retain key associations, use uasort() - see comparison of array sorting functions in the manual

Ref : https://bit.ly/3i77vCC