You can also do this with PHPExcel. Please find the code below which works fine to me. The code below does not contain a file browser and PHPExcel.php This can be automated to your system by making loop with reading number of files in a folder <?php /* Author: Rajan Maharjan Website: […]
Import xls data to MYSQL
mysql_connect(“localhost”,”root”,””) or die(“cannot connect”); mysql_select_db(“db_name”) or die(“cannot find database”); $dataSheetFile=”sample_csv.csv”; $counter=0; if (($handle = fopen($dataSheetFile, “r”)) !== FALSE) { while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE) { $university=htmlentities(trim($data[0])); $faculty=htmlentities(trim($data[1])); $research_sub_group=htmlentities(trim($data[2])); $themenband=htmlentities(trim($data[3])); $street=htmlentities(trim($data[4])); $zipcode=htmlentities(trim($data[5])); $city=htmlentities(trim($data[6])); $website=htmlentities(trim($data[7])); $counter++; mysql_query(“INSERT INTO research_sub_group set university=’$university’, faculty=’$faculty’, research_sub_group=’$research_sub_group’, themenband=’$themenband’, street=’$street’, zip=’$zipcode’,city=’$city’,website=’$website'”); } } echo […]
Open CSV File using PHP
// place this code inside a php file and call it f.e. “download.php” $_GET[‘download_file’]=’websiteData.csv’; $path = $_SERVER[‘DOCUMENT_ROOT’].”/wedev/”; // change the path to fit your websites document structure $fullPath = $path.$_GET[‘download_file’]; if ($fd = fopen ($fullPath, “r”)) { $fsize = filesize($fullPath); $path_parts = pathinfo($fullPath); $ext = strtolower($path_parts[“extension”]); switch ($ext) { case […]
array_slice
$input = array(“red”, “green”, “blue”, “yellow”); $splice1=array_splice($input, 1, count($input), “orange”); $splice2=array_splice($input, 1, count($input)-1, “mango”); print_r($splice1); echo ”; print_r($splice2);
PHP Array Pagination
$path=getcwd().”\images”; if(is_dir($path)){ $arrayPhotos=array(); if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { if($file!=”..” && $file!=”.” && strtolower($file)!=”thumbs.db”) if(!in_array($file,$arrayPhotos)) array_push($arrayPhotos,$file); } closedir($dh); } } asort($arrayPhotos); // Include the pagination class include ‘pagination.class.php’; // Create the pagination object $pagination = new pagination; // If we have an array with […]
Create image from text using PHP
function createImageFromText($text,$fontSize=12,$fontColor=”#FFF”,$imageSize=array(300,50),$fontFamily=”arial.ttf”,$rotationAngle=0, $xCoordinate=20, $yCordinate=120){ header(“Content-type: image/png”); //Picture Format header(“Expires: Mon, 01 Jul 2003 00:00:00 GMT”); // Past date header(“Last-Modified: ” . gmdate(“D, d M Y H:i:s”) . ” GMT”); // Consitnuously modified header(“Cache-Control: no-cache, must-revalidate”); // HTTP/1.1 header(“Pragma: no-cache”); // NO CACHE /*image generation code*/ //create Image of size 350px […]