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


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.