Skip to content

Instantly share code, notes, and snippets.

@amin007
Last active December 27, 2015 05:28
Show Gist options
  • Save amin007/7273902 to your computer and use it in GitHub Desktop.
Save amin007/7273902 to your computer and use it in GitHub Desktop.
mencari nama fail php dalam folder dan subfolder
<?php
/*
* Ini fail fungsi.php
* Dalam ini ada fungsi untuk cari imej dalam folder dan subfolder
*/
function cari_imej($namaFail,$strDir)
{
//require_once ('public/skrip/listfiles2/dir_functions.php');
if ( isset($namaFail) && empty($namaFail) )
{
$cariImej = null;
}
else
{
// You can modify this in case you need a different extension
$strExt = "php"; // jpg/tif/png/txt
// This is the full match pattern based upon your selections above
$pattern = "*" . $namaFail . "*." . $strExt;
$cariImej = GetMatchingFiles(GetContents($strDir),$pattern);
}
//print_r($cariImej);
return $cariImej;
}
// lisfile2 - mula
function GetMatchingFiles($files, $search)
{
// Split to name and filetype
if(strpos($search,"."))
{
$baseexp=substr($search,0,strpos($search,"."));
$typeexp=substr($search,strpos($search,".")+1,strlen($search));
}
else
{
$baseexp=$search;
$typeexp="";
}
// Escape all regexp Characters
$baseexp=preg_quote($baseexp);
$typeexp=preg_quote($typeexp);
// Allow ? and *
$baseexp=str_replace(array("\*","\?"), array(".*","."), $baseexp);
$typeexp=str_replace(array("\*","\?"), array(".*","."), $typeexp);
// Search for Matches
$i=0;
$matches=null; // $matches adalah array()
foreach($files as $file)
{
$filename=basename($file);
if(strpos($filename,"."))
{
$base=substr($filename,0,strpos($filename,"."));
$type=substr($filename,strpos($filename,".")+1,strlen($filename));
}
else
{
$base=$filename;
$type="";
}
if(preg_match("/^".$baseexp."$/i",$base) && preg_match("/^".$typeexp."$/i",$type))
{
$matches[$i]=$file;
$i++;
}
}
return $matches;
//return $matches;
}
// Returns all Files contained in given dir, including subdirs
function GetContents($dir,$files=array())
{
if(!($res=opendir($dir))) exit("$dir doesn't exist!");
while(($file=readdir($res))==TRUE)
if($file!="." && $file!="..")
if(is_dir("$dir/$file")) $files=GetContents("$dir/$file",$files);
else array_push($files,"$dir/$file");
closedir($res);
return $files;
}
// listfile2 - tamat
?>
<?php
/*
* Ini fail index.php
* Dalam ini kita isytiharkan
* 1. zon masa kita pada Asia/Kuala Lumpur
* 2. setkan tatarajah sistem
* 3. masukkan semua fail class dari folder PUSTAKA
* 4. istihar class Mulakan
*/
// 1. isytiharkan zon masa => Asia/Kuala Lumpur
date_default_timezone_set('Asia/Kuala_Lumpur');
// 2. setkan tatarajah sistem
require 'tatarajah.php';
// 3. masukkan semua fail class dari folder PUSTAKA
// Also spl_autoload_register (Take a look at it if you like)
function __autoload($class)
{
require PUSTAKA . $class . '.php';
}
// 4. istihar class Mulakan
$app = new Mulakan();
<?php
/* Laporan tahap kesilapan kod PHP */
//error_reporting(E_ALL);
// Always provide a TRAILING SLASH (/) AFTER A PATH
define('URL', dirname('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']) . '/');
// 4 folder utama
define('KAWAL', 'aplikasi/kawal/');
define('PAPAR', 'aplikasi/papar/');
define('TANYA', 'aplikasi/tanya/');
define('PUSTAKA', 'aplikasi/pustaka/');
// set for mysql
define('DB_TYPE', 'mysql');
define('DB_HOST', 'localhost');
define('DB_NAME', '***');
define('DB_USER', '***');
define('DB_PASS', '***');
// The sitewide hashkey, do not change this because its used for passwords!
// This is for other hash keys... Not sure yet
define('HASH_GENERAL_KEY', 'MixitUp200');
// This is for database passwords only
define('HASH_PASSWORD_KEY', 'catsFLYhigh2000miles');
// Fungsi Global
include PUSTAKA . 'Fungsi.php';
@amin007
Copy link
Author

amin007 commented Nov 3, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment