dreamwest Posted July 6, 2009 Share Posted July 6, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/164994-delete-multiple-files/ Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/164994-delete-multiple-files/#findComment-869999 Share on other sites More sharing options...
dreamwest Posted July 6, 2009 Author Share Posted July 6, 2009 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/164994-delete-multiple-files/#findComment-870039 Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 not a problem Quote Link to comment https://forums.phpfreaks.com/topic/164994-delete-multiple-files/#findComment-870042 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.