I'll give you one way of finding those folders:
// $str = 'ftp://domain.com/Document/EBook/ThisDoc.pdf'; // uncomment this line and comment the next one to see the other result...
$str = 'ftp://domain.com/Document/Tutorial/ThisTut.pdf';
preg_match('#(\w+)$#', dirname($str), $match);
echo $match[1]; // ouputs Tutorial
If you can collect all your urls into an array...
$str = array('ftp://domain.com/Document/Tutorial/ThisTut.pdf','ftp://domain.com/Document/EBook/ThisDoc.pdf');
foreach($str as $val){
preg_match('#(\w+)$#', dirname($val), $match);
echo $match[1] . '<br />';
}
outputs:
Tutorial
EBook
In each loop of foreach, you can store the end result for $match[1] into your database. There you have it 🙂