File Validation

Here is a simple function to valid a image file. You can modify/add extensions and mime type according to your needs. function checkImageTypeArray($file) { $errorarray=array(); $allowExtension = array(“gif”, “jpeg”, “jpg”, “png”); $allowMime = array(“image/gif”, “image/jpesg”, “image/pjpeg”, “image/x-png”,”image/png”); $getFileExtension = pathinfo($file[‘name’],PATHINFO_EXTENSION);…

String Search

1) strpos or stripos— strpos find the position of firstoccurance of string and returns false if string is not found. String position starts with 0 so dont compare with 0 for finding string $a = ‘How arEd you?’; if(strpos($a,’are’)!==false) {…

Transaction in PHP Mysql

This is how easily you can implement tractions in mysqli and PHP. $link = mysqli_connect(‘localhost’,’root’,”,’test’); // Check connection if (mysqli_connect_errno()) { die(‘error’); } mysqli_autocommit($link, FALSE); //disable autocommit $query=”insert into tb1 (username,pwd) values(‘pp’,’sdsd’)”; $queryres=mysqli_query($link, $query); if(!$queryres) { echo “error first query”;…

Get Project Path with Protocol

Here is how you can absolute project url with for http and htts both:: $protocol = stripos($_SERVER[‘SERVER_PROTOCOL’],’https’) === true ? ‘https://’ : ‘http://’; echo $protocol.$_SERVER[‘HTTP_HOST’].$_SERVER[‘PHP_SELF’];

Page 3 of 41234