Wednesday, January 13, 2016

Create and Embed Barcodes using PHP

PHP GD Library 
In case of Debian Linux just run command :

#sudo apt-get install php5-gd

Barcode script : 
View the code here:

That Scripts generates barcodes in four barcode formats including Code 128, Code 39, Code 2of5, and Codabar. With a little over 100 lines of code you have the options of “vertical” or “horizontal” display, varying barcode heights, and one of four barcode formats.

How to embed in HTML code:
Example 1:
<img alt="testing" src="/yourfilelocation/barcode.php" />
Example 2 (with text data):
<img alt="testing" src="/yourfilelocation/barcode.php?text=testing" />
Example 3 (with codetype, size, text)
<img alt="TESTING" src="/yourfilelocation/barcode.php?codetype=Code39&size=40&text=TESTING" />

Thursday, July 9, 2015

Create list of all installed packages by date in Ubuntu or Debian

#creates file with a list of all packages installed by date
#append all info from archived logs

mycount=$(ls -l /var/log/dpkg.log.*.gz | wc -l)
nlogs=$(( $mycount + 1 ))

while [ $i -le $nlogs ]
if [ -e /var/log/dpkg.log.$i.gz ]; then
zcat /var/log/dpkg.log.$i.gz | grep "\ install\ " >> $HOME/packagetmp.txt
i=$(( $i+1 ))

#Next append all info from unarchived logs
nulogs=$(ls -l /var/log/dpkg.log.* | wc -l)
nulogs=$(( $nulogs - $nlogs + 1 ))
while [ $i -le $nulogs ]
if [ -e /var/log/dpkg.log.$i ]; then
cat /var/log/dpkg.log.$i | grep "\ install\ " >> $HOME/packagetmp.txt
i=$(( $i+1 ))

#Now append current log
cat /var/log/dpkg.log | grep "\ install\ " >> $HOME/packagetmp.txt
#sort file data by date

sort -n $HOME/pkgtmp.txt > $HOME/packageinstalls.txt
rm $HOME/packagetmp.txt
exit 0

Thursday, July 24, 2014

Import a Large CSV file to MySQL commend line

Using the mysqlimport utility run below command.

mysqlimport  --ignore-lines=1 --fields-terminated-by=,--columns='ID,columnName1,columnname2, columnname3' --local -u root -p Databasename /pathtocsvfile/tablename.csv

You must put the absolute path of the csv file for it to register with 
the utility. The “tablename.csv” has to match the name of the table in 
your mysql database.

For more information on the mysqlimport utility: Click Here

Wednesday, May 28, 2014

Validation uploaded File in php

if(isset($_FILES['uploaded_file'])) {
    $errors     = array();
    $maxsize    = 1000000;
    $acceptable = array(

    if(($_FILES['uploaded_file']['size'] >= $maxsize) || ($_FILES["uploaded_file"]["size"] == 0)) {
        $errors[] = 'File too large. File must be less than 1MB.';

    if(!in_array($_FILES['uploaded_file']['type'], $acceptable)) && (!empty($_FILES["uploaded_file"]["type"]))) {
    $errors[] = 'Invalid file type. Only PDF, JPG, GIF and PNG types are accepted.';

if(count($errors) === 0) {
    move_uploaded_file($_FILES['uploaded_file']['tmpname'], '/store/to/location.file');
} else {
    foreach($errors as $error) {
        echo '<script>alert("'.$error.'");</script>';

    die(); //Ensure no more processing is done

Saturday, October 27, 2012

Run a script at logout/shutdown/restart on ubuntu

If the script name is, then do the following steps and also make sure that the script is executable :

sudo cp /etc/init.d
sudo ln -s /etc/init.d/ /etc/rc0.d/
sudo ln -s /etc/init.d/ /etc/rc6.d/