Autor Zpráva
Jaspe
Profil *
Nemáte někdo nějaký tip na script v PHP, který umí procházet zadaný adresář, umí vyhledávat, možnost tagovat soubory, aby to nějak schopně vypadalo, ikonky podle typu souborů, náhledy atd...?
Radek9
Profil
Prostuduj si funkce:
opendir() a readdir() či scandir()
sort()
stristr()
explode()
atd.
A cykly:
foreach
while
a pokud bys to chtěl i stránkovat, tak by se hodil i for
Jaspe
Profil *
Vím jak to udělat, nemám na to čas, spíše jsem hledal tip na nějaké hotové řešení...
fopen
Profil *
Tak tu niekde by som začal, ide o triedu, pomocou ktorej sa da získať pole položiek z adresára aj z podrobným infom...
<?php
class Directory {
	
	public $HiddenItems = array();
	public $ExtensionFilter;
	
	public function ParseDirectory($path='.') {
		
		if($dir_obj = dir($path)){
			
			$dir['path'] = $dir_obj->path;
			$dir['hadle'] = $dir_obj->handle;
			$dir['dirscount'] = 0;
			$dir['filescount'] = 0;
			$dir['totalsize'] = 0;
			$dir['humantotalsize'] = 0;
			
			while(FALSE!==($item=$dir_obj->read())) {
				
				if(!in_array($item, $this->HiddenItems)) {
					
					if($item != '.' && $item != '..') {
						
						$info=Directory::ItemInfo($dir_obj->path.'/'.$item);
						
						if(@is_dir($dir_obj->path.'/'.$item)) {
							$dir['dirs'][$item] = $info;
							$dir['dirs'][$item]['encoded_item'] = urlencode($item);
							$dir['dirscount']+=1;
						}
						
						if(@is_file($dir_obj->path.'/'.$item)) {
							
							if(!empty($this->ExtensionFilter)) {
								if($this->ExtensionFilter==$info['extension']){
									$dir['files'][$item] = $info;
									$dir['files'][$item]['encoded_item'] = urlencode($item);
									$dir['filescount']+=1;
									$dir['totalsize']+=$info['size'];
								}
							} else {
								$dir['files'][$item] = $info;
								$dir['files'][$item]['encoded_item'] = urlencode($item);
								$dir['filescount']+=1;
								$dir['totalsize']+=$info['size'];
							}
						}
						
						if(@is_link($dir_obj->path.'/'.$item)) {
							$dir['links'][$item] = $info;
							$dir['links'][$item]['encoded_item'] = urlencode($item);
							$dir['linkscount']+=1;
						}
					}
				}
			}
			$dir['humantotalsize'] = Directory::HumanFileSize($dir['totalsize']);
			$dir_obj->rewind();
			$dir_obj->close();
			
			return $dir;
			
		} else {
			return FALSE;
		}
	}

	public function ItemInfo($filename) {
		/*** pathinfo() Sample
		$path_info['dirname'] => dir.inclusions
		$path_info['basename'] => file_info.class.php
		$path_info['extension'] => php
		$path_info['name'] => file_info.class
		*/	
		if($path_info=@pathinfo($filename)){
			if($dot=@strrpos($path_info['basename'],".")){
				$path_info['name']=substr($path_info['basename'],0,$dot);
			}
		}
		
		/*** If is item directory - is ignored */
		if(!empty($path_info['extension'])) {
			$path_info['extension'] = strtolower($path_info['extension']);
		}
		
		/*** Returns the hash as a 32-character hexadecimal number */
		$path_info['file_hash'] = md5($path_info['basename']);
		
		/*** stat() Sample
		device					$path_info[dev] => 774
		inode						$path_info[ino] => 736513
		inode protection mode			$path_info[mode] => 33188
		number of links				$path_info[nlink] => 1
		user id of owner				$path_info[uid] => 103
		group id owner				$path_info[gid] => 72
		device type if inode device		$path_info[rdev] => 0
		size in bytes				$path_info[size] => 12431
		time of last access			$path_info[atime] => 1162046454
		time of last modification		$path_info[mtime] => 1161982617
		time of last change			$path_info[ctime] => 1161982617
		blocksize for filesystem I/O *	$path_info[blksize] => 4096
		number of blocks allocated		$path_info[blocks] => 32
		*/		
		if($stat=@stat($filename)){
			if(is_array($stat)){
				foreach($stat as $key=>$value){
					if(!is_numeric($key)){
						$path_info[$key]=$value;
					}
				}
			}
			$path_info['humansize'] = Directory::HumanFileSize($path_info['size']);
			$path_info['chmod'] = substr(sprintf('%o',$path_info['mode']),-4);
		}
		
		/*** getimagesize() Sapmle
		[0] => 253
		[1] => 384
		[2] => 2						// image_typenum
		[3] => width="253" height="384"
		[bits] => 8
		[channels] => 3
		[mime] => image/jpeg
		
		image_typenum		imagetype  						image_mime
		------------------------------------------------------------------------------------------------
		1				IMAGETYPE_GIF 						image/gif
		2				IMAGETYPE_JPEG 						image/jpeg
		3				IMAGETYPE_PNG 						image/png
		4				IMAGETYPE_SWF 						application/x-shockwave-flash
		5				IMAGETYPE_PSD 						image/psd
		6				IMAGETYPE_BMP 						image/bmp
		7				IMAGETYPE_TIFF_II (intel byte order) 		image/tiff
		8				IMAGETYPE_TIFF_MM (motorola byte order) 	image/tiff
		9				IMAGETYPE_JPC 						application/octet-stream
		10				IMAGETYPE_JP2 						image/jp2
		11				IMAGETYPE_JPX 						application/octet-stream
		12				IMAGETYPE_JB2 						application/octet-stream
		13				IMAGETYPE_SWC 						application/x-shockwave-flash
		14				IMAGETYPE_IFF 						image/iff
		15				IMAGETYPE_WBMP 						image/vnd.wap.wbmp
		16				IMAGETYPE_XBM 						image/xbm
		17				IMAGETYPE_ICO 						image/vnd.microsoft.icon
		------------------------------------------------------------------------------------------------
		*/
		if($image=@getimagesize($filename)){
			$path_info['image_width']=$image[0];
			$path_info['image_height']=$image[1];
			$path_info['image_typenum']=$image[2];
			$path_info['image_size_str']=$image[3];
			$path_info['image_bits']=$image['bits'];
			$path_info['image_channels']=$image['channels'];
			$path_info['image_mime']=$image['mime'];
		}

		return $path_info;
	}
	
	public function HumanFileSize($size) {
		if($size==0){return("0 bytes");}
		$filesizename=array(" bytes"," kb"," mb"," gb"," tb"," pb"," eb"," zb"," yb");
		return round($size/pow(1024,($i=floor(log($size,1024)))),2).$filesizename[$i];
	}

}
?>

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: