Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

ftp_alloc()

Example

Allocate space for a file and then upload it to the FTP server.

<?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);
?>

Definition and Usage

The ftp_alloc() function reserves space for a file to be uploaded to the FTP server.

Note: This command is not supported by many FTP servers!

Syntax

ftp_alloc(ftp_conn, filesize, result);

Parameter Values

Parameter

Description

ftp_conn

Mandatory. Specifies the FTP connection to use.

filesize

Mandatory. Specifies the number of bytes to allocate.

result

Optional. Specifies a variable to store the server’s response.

Technical Details

 

Return Value:

Returns TRUE on success and FALSE on failure.

PHP Version:

5+