I want to get files from a remote server using ftp function in php. I use the ftp_nlist method to get the files but the problem is when I loop through it it contains full path with the file name. I want only file names
<?php
$ftp_server = "host.com";
$ftp_connection = ftp_connect($ftp_server)
or die("Could not connect to $ftp_server");
$ftp_username="user";
$ftp_userpass ="password";
$login = ftp_login($ftp_connection, $ftp_username, $ftp_userpass);
$path = "mainpath/assets/Template/Top/";
$contents = ftp_nlist($ftp_connection, $path);
foreach($contents as $key=>$dat) {
echo $contents[$key];
}
?>
Which I get the files but the path contains namemainpath/assets/Template/Top/file.ext
I just want file.ext