Jump to content

delete multiple files


dreamwest

Recommended Posts

Im trying to delete multiple files by ftp, i can do this with a single file but how can i do it to delete multiple files

 

$file = "image.jpg"; //deletes this single file
//$files = array(image1.jpg, image2.jpg, image3.jpg);

$target_ftp_server			= "server";
$target_ftp_user			= "user";
$target_ftp_pass			= "pass";
$target_ftp_path_thumb	= "/";

// connect to target ftp server
$target_conn = ftp_connect($target_ftp_server) or die("Could not connect to target_ftp_server!");
ftp_login($target_conn, $target_ftp_user, $target_ftp_pass);

// switch to passive mode if behind a firewall 
ftp_pasv($target_conn, true );

// change to the target path
ftp_chdir($target_conn, $target_ftp_path_thumb);

// delete file
if (ftp_delete($target_conn, $file)) {

echo "<font color='red'>Removed!</font>";

} else {
echo "could not delete $file\n ";
}

// close all ftp connections
ftp_close($target_conn);

Link to comment
https://forums.phpfreaks.com/topic/164994-delete-multiple-files/
Share on other sites

like this?

 


<?php

//$file = "image.jpg"; //deletes this single file
$files = array(image1.jpg, image2.jpg, image3.jpg);

$target_ftp_server         = "server";
$target_ftp_user         = "user";
$target_ftp_pass         = "pass";
$target_ftp_path_thumb   = "/";

   // connect to target ftp server
$target_conn = ftp_connect($target_ftp_server) or die("Could not connect to target_ftp_server!");
   ftp_login($target_conn, $target_ftp_user, $target_ftp_pass);

   // switch to passive mode if behind a firewall
   ftp_pasv($target_conn, true );

   // change to the target path
   ftp_chdir($target_conn, $target_ftp_path_thumb);

// delete file
foreach($files as $deleteme){
if (ftp_delete($target_conn, $deleteme)) {

echo "<font color='red'>Removed!</font>";

} else {
echo "could not delete $file\n ";
}

}//end foreach

// close all ftp connections
ftp_close($target_conn);


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.