PHP ftp delete

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

PHP : ftp_delete() function

Description

The ftp_delete() function is used to delete a file on the FTP server.

Version

(PHP 4 and above)

Syntax

ftp_delete(ftp_connection, file_name)

Parameters

Name

Description

Required /
Optional

Type

ftp_connection

The link identifier of the FTP connection.

Required

Resource

file_name

The file to delete.

Required

String

 

Return value

TRUE on success or FALSE on failure.

Value Type : Boolean.

Example :

  1. $ftp_server="192.168.0.2";  

  2. $ftp_user_name="abc123";  

  3. $ftp_user_pass="abc123";  

  4. $file = 'D:/ds/abc123.txt';  

  5. // set up basic connection  

  6. $conn_id = ftp_connect($ftp_server);  

  7. // login with username and password  

  8. $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);  

  9. // try to delete $file  

  10. if (ftp_delete($conn_id, $file)) {  

  11.  echo $file."deleted successful ";  

  12. } else {  

  13.  echo "could not delete".$file;  

  14. }  

  15. // close the connection  

  16. ftp_close($conn_id);  

  17. ?>        

Output :

could not delete D:/ds/abc123.txt