PHP FTP

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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 :

  1. $file = "d: est.txt";  

  2. /* connect to the server */  

  3. $conn_id = ftp_connect('192.168.0.2');  

  4. $login_result = ftp_login($conn_id, 'abc123', 'abc123');  

  5. if (ftp_alloc($conn_id, filesize($file), $result)) {  

  6.   echo "Space successfully allocated on server.  Sending $file. ";  

  7.   ftp_put($conn_id, 'D:/ds', $file, FTP_BINARY);  

  8. } else {  

  9.   echo "Unable to allocate space on server.  Server said: $result ";  

  10. }  

  11. ftp_close($conn_id);  

  12. ?>