php8.5
Home/ Manual/ ftp / functions/ ftp_delete

ftp_delete

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Deletes a file on the FTP server

Description

ftp_delete(FTP\Connection $ftp, string $filename): bool

ftp_delete() deletes the file specified by filename from the FTP server.

Parameters

ftp

Ftp

filename

The file to delete.

Return Values

Success

Changelog

VersionDescription

Examples

ftp_delete() example

php
<?php
$file = 'public_html/old.txt';

// set up basic connection
$ftp = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);

// try to delete $file
if (ftp_delete($ftp, $file)) {
 echo "$file deleted successful\n";
} else {
 echo "could not delete $file\n";
}

// close the connection
ftp_close($ftp);
?>

Source: reference/ftp/functions/ftp-delete.xml · from the official PHP manual (php/doc-en)