kohana-storage
kohana-storage copied to clipboard
'Not found class Storage_Connection_Ftp'
I have a default kohana 3.3.1 and does not work properly FTP class. Fixed names of classes and files from Storage_Connection_FTP to Storage_Connection_Ftp and helped. Perhaps only in my case but it was required. :)
BTW: Another litle problem with class Kohana_Storage_Connection_Ftp . Wront information about files. So i change the function :
protected function _listing($path, $listing) { $this->_load();
ftp_chdir($this->_connection, $path);
foreach (ftp_nlist($this->_connection, NULL) as $name)
{
if ($name[0] === '.' OR $name[strlen($name) - 1] === '~')
continue;
$item = ftp_raw($this->_connection, 'MLST ' . $name);
$item = explode(';', $item[1]);
$name = $this->search_element_in_array($item);
//$name = trim($item[7]);
$_path = $path . Storage::DELIMITER . $name;
// poprawiono z $item[0]
($find = $this->search_element_in_array($item, "type"))? $find: "";
$find_type = end($find);
//$segments = explode("=", $item[2]);
//$type = end($segments);
$type = $find_type;
if ($type == 'dir')
{
echo "dir";
$object = Storage_Directory::factory($_path, $this);
}
else if ($type == 'file')
{
$size = 0;
$modified = 0;
foreach($item as $search_dir) {
$tmp_dir = explode("=", $search_dir);
if(isset($tmp_dir[0])) {
if("size" === $tmp_dir[0]) {
$size = $tmp_dir;
}else if("250-modify" === $tmp_dir[0]) {
$modified = $tmp_dir;
}
}
}
//$size = explode('=', $item[1]);
//$modified = explode('=', $item[2]);
$object = Storage_File::factory($_path, $this)
->size(end($size))
->modified(strtotime(end($modified)));
}
else
throw new Storage_Exception('Unkown type: ' . $type);
$listing->set($object);
}
ftp_chdir($this->_connection, $this->_origin);
return $listing;
}
/**
* Search key in array
*
* @param array $array
* @param string $key
* @return (boolean|array)
*/
public function search_element_in_array($array, $key = null) {
if(isset($array) && !empty($array) && is_array($array)) {
$check = false;
$return_value = array();
if(null === $key) {
$tmp_name = array_reverse($array);
$return_value = $tmp_name[0];
$check = true;
}else {
foreach($array as $element) {
$tmp_array = explode("=", $element);
if(isset($tmp_array[0])) {
if($key === $tmp_array[0]) {
$return_value = $tmp_array;
$check = true;
break;
}
}
}
}
if($check && !empty($return_value)) {
return $return_value;
}else {
return false;
}
}else {
return false;
}
}
Use:
$ftp = Storage::factory('ftp', array('username' => 'username', 'password' => 'password));
$files = $ftp->listing('/files');
if (isset($files) && !empty($files)) {
foreach ($files as $listing) {
if ($listing->is_file()) {
echo $listing->name(). " | ". $listing->modified(). " | ". $listing->mime(). " | ". $listing->size(). "
";
} else if ($listing->is_directory()) {
// We can also iterate over this $listing
object because it is an
// instance of Storage_Directory
echo $listing->name();
}
}
}
So it's all :P