Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Tuesday, April 26, 2011

Free Download Scripts and Source Code

Free Download Scripts and Source Code Free Download Scripts and Source Code, Clone Script, Nulled Script, Script Example, Flash Action Script, Javascript, Java, JQuery, Ajax, PHP, CSS, HTML, etc.
Reference: http://scriptexample.blogspot.com/2010/10/21-amazing-jquery-tabs-collection.html

Tuesday, June 22, 2010

copy all files from 1 folder to another folder

Here is the function which is used for copy all files from 1 folder to another folder
=======================================
function copydir($dirname1,$dirname2) {

if (is_dir($dirname1))

$dir_handle = opendir($dirname1);
if (!$dir_handle)
return false;
while($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {
if (!is_dir($dirname1."/".$file))
$tempfile=fopen($dirname2."/".$file,"w+");
copy($dirname1."/".$file,$dirname2."/".$file);
//unlink($dirname1."/".$file);
}
}
closedir($dir_handle);
return true;
}

Here are the files which contain upload file function and you can upload your file by using these files.
=======================================

1./ http://www.esnips.com/doc/1bc71467-47d8-4085-9afd-d2073c725513/upload
2./ http://www.esnips.com/doc/33d8a913-5bc7-498b-9c26-74f59af4dc07/upload-file

Wednesday, June 24, 2009

A Complete E-mail Validation Function

Today, I have something to do with an email validate then I had search by google to find all requirement i need to use, a few menuts later I have found this below:
but I am not still main hope of you, however it it the main concept for the email validation and easy use in PHP and not complicated in thinking, coz everything is completed.
//===============================================

Validate an email address.
Provide email address (raw input)
Returns true if the email address has the email
address format and the domain exists.
*/
function validEmail($email)
{
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen <> 64)
{
// local part length exceeded
$isValid = false;
}
else if ($domainLen <> 255)
{
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.')
{
// local part starts or ends with '.'
$isValid = false;
}
else if (preg_match('/\\.\\./', $local))
{
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
// character not valid in domain part
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain))
{
// domain part has two consecutive dots
$isValid = false;
}
else if
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
str_replace("\\\\","",$local)))
{
// character not valid in local part unless
// local part is quoted
if (!preg_match('/^"(\\\\"|[^"])+"$/',
str_replace("\\\\","",$local)))
{
$isValid = false;
}
}
if ($isValid && !(checkdnsrr($domain,"MX") ||
↪checkdnsrr($domain,"A")))
{
// domain not found in DNS
$isValid = false;
}
}
return $isValid;
}
//===============================================
Reference: http://www.linuxjournal.com/article/9585

Thursday, June 18, 2009

calculate (year, month, date) with PHP DateDiff Function

Today, I am really stress with the calculate the number of year, month, date which calcuated from the expired date with the current date, that so, I have search by google then making decision on the following style to improve my problem, and I am still on hesitat it yet, coz it's not fully requirement which I need, but this below function also the rest of solving problem with date... By this point, it show the number of year, or month, or date, .....

function datediff($interval, $datefrom, $dateto, $using_timestamps = false) {
/*
$interval can be:
yyyy - Number of full years
q - Number of full quarters
m - Number of full months
y - Difference between day numbers
(eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
d - Number of full days
w - Number of full weekdays
ww - Number of full weeks
h - Number of full hours
n - Number of full minutes
s - Number of full seconds (default)
*/

if (!$using_timestamps) {
$datefrom = strtotime($datefrom, 0);
$dateto = strtotime($dateto, 0);
}
$difference = $dateto - $datefrom; // Difference in seconds

switch($interval) {

case 'yyyy': // Number of full years

$years_difference = floor($difference / 31536000);
if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom)+$years_difference) > $dateto) {
$years_difference--;
}
if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto)-($years_difference+1)) > $datefrom) {
$years_difference++;
}
$datediff = $years_difference;
break;

case "q": // Number of full quarters

$quarters_difference = floor($difference / 8035200);
while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($quarters_difference*3), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
$months_difference++;
}
$quarters_difference--;
$datediff = $quarters_difference;
break;

case "m": // Number of full months

$months_difference = floor($difference / 2678400);
while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
$months_difference++;
}
$months_difference--;
$datediff = $months_difference;
break;

case 'y': // Difference between day numbers

$datediff = date("z", $dateto) - date("z", $datefrom);
break;

case "d": // Number of full days

$datediff = floor($difference / 86400);
break;

case "w": // Number of full weekdays

$days_difference = floor($difference / 86400);
$weeks_difference = floor($days_difference / 7); // Complete weeks
$first_day = date("w", $datefrom);
$days_remainder = floor($days_difference % 7);
$odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
if ($odd_days > 7) { // Sunday
$days_remainder--;
}
if ($odd_days > 6) { // Saturday
$days_remainder--;
}
$datediff = ($weeks_difference * 5) + $days_remainder;
break;

case "ww": // Number of full weeks

$datediff = floor($difference / 604800);
break;

case "h": // Number of full hours

$datediff = floor($difference / 3600);
break;

case "n": // Number of full minutes

$datediff = floor($difference / 60);
break;

default: // Number of full seconds (default)

$datediff = $difference;
break;
}

return $datediff;

}

?>

reference : http://www.addedbytes.com/php/php-datediff-function/

Tuesday, May 26, 2009

website title randomization

Here, this a smallest website tilte randomization code in php which not complicated but it also important for the first step learning with php, I just got it from the website and want to keep it as properties for the general
learning, and still hope that it also concerning with the rest of studying. let me detail code as below:


// get a random number $randomize = rand(0, 4); // Change four to how many arrays you haveecho ($title[$randomize]); ?>see it in action.
$title[0] = "Web title 0"; // Title 0

$title[1] = "Web title 1"; // Title 1

$title[2] = "Web title 2"; // Title 2

$title[3] = "Web title 3"; // Title 3
$title[4] = "Web title 4"; // Title 4

// get a random number

$randomize = rand(0, 4); // Change four to how many arrays you have

Thursday, September 18, 2008

Method #1

The first method is using Pager to create the links only, and let you fetch the relevant records on your own. Instead of passing the array of data to paginate to Pager, you just pass the number of records. In the following example, we'll fetch the records from a table containing some products. The PEAR::MDB2 DBAL is used here, but how you fetch the records isn't relevant.


require_once 'Pager/Pager.php';
require_once 'MDB2.php';

//skipped the db connection code...
//let's just suppose we have a valid db connection in $db.

//first, we use Pager to create the links
$num_products = $db->queryOne('SELECT COUNT(*) FROM products');
$pager_options = array(
'mode' => 'Sliding',
'perPage' => 10,
'delta' => 2,
'totalItems' => $num_products,
);

$pager = Pager::factory($pager_options);

//then we fetch the relevant records for the current page
list($from, $to) = $pager->getOffsetByPageId();
//set the OFFSET and LIMIT clauses for the following query
$db->setLimit($pager_options['perPage'], $from - 1);
$query = 'SELECT prod_name, prod_description FROM products';
$products = $db->queryAll($query, null, MDB2_FETCHMODE_ASSOC);

//show the results
echo '
    ';
    foreach ($products as $product) {
    echo '
  • '.$product['prod_name'].': '.$product['prod_description'].'
  • ';
    }
    echo '
';

//show the links
echo $pager->links;
?>

Reference

Paginating Database Records (PHP)

class Users extends Model{

function Users(){

// call the Model constructor

parent::Model();

// load database class and connect to MySQL

$this->load->database();

}

function getAllUsers(){

$query=$this->db->get('users');

if($query->num_rows()>0){

// return result set as an associative array

return $query->result_array();

}

}

function getUsersWhere($field,$param){

$this->db->where($field,$param);

$query=$this->db->get('users');

// return result set as an associative array

return $query->result_array();

}

// get 5 rows at a time

function getUsers($row){

$query=$this->db->get('users',5,$row);

if($query->num_rows()>0){

// return result set as an associative array

return $query->result_array();

}

}

// get total number of users

function getNumUsers(){

return $this->db->count_all('users');

}

}


Reference