Saturday, February 1, 2014

PHP Image upload , Saving link to Database complete tutorial

This blog is dedicated to all our visitors who asked me to publish a working tutorial on  image upload  using PHP and Saving its path to Mysql Table.
PHP Image upload , Saving  link to Database

How to do that :
First we will create a file called install.php , it will create a database called
myimages and a table  named imgtables and also create a folder called gallery where we are going to store  images.

Create a file name install.php
------------------------------------------------------
<?php
/*
file name : Install.php
purpose : creating a database name myimages
and table imgtables
Create by : Sanjay Prasad
sonzoy@gmail.com
http://www.openplus.in
*/

$db=mysqli_connect("localhost","root","");

if($db->connect_errno){
    echo "Error <br/>".$sp->error;
}

$query="create database if not exists myimages";

if($db->query($query)){
     echo "Created database myimages ..<br/>";   
    
     $sp=mysqli_connect("localhost","root","","myimages");
         if($sp->connect_errno){
                echo "Error <br/>".$sp->error;
            }
           
            $tbquery="create table if not exists imgtables(
            id int unsigned auto_increment primary key,
            imgurl varchar(255),
            date varchar(100)


            )engine='InnoDB'";
           
            if($sp->query($tbquery)){
                echo "Table imgtables created Successfully  ..<br/> ";   
            }else{
                echo "Error <br/>".$sp->error;       
            }
           
            //creating directory gallery
           
            if(mkdir("gallery",0777)){
                echo "Folder gallery create successfully";
            }else{
                echo "Error Creating Directory";
            }

    }
else{
    echo "Error <br/>".$sp->error;   
    }   

?>

Now We have to create a file name gallery.php, which will upload images to folder gallery and saved their name like flower.jpg on table filed imgurl.

gallery.php

<!DOCTYPE html>
<html lang="en">
<head>
<title>File Uploading</title>
<meta charset="utf-8" />
</head><body>
<?php
$sp=mysqli_connect("localhost","root","","myimages");
         if($sp->connect_errno){
                echo "Error <br/>".$sp->error;
}

$path="gallery/";

if(isset($_POST['upload']))
{

$path=$path.$_FILES['file_upload']['name'];
   
if(move_uploaded_file($_FILES['file_upload']['tmp_name'],$path))
{
echo " ".basename($_FILES['file_upload']['name'])." has been uploaded<br/>";
echo '<img src="gallery/'.$_FILES['file_upload']['name'].'" width="48" height="48"/>';
$img=$_FILES['file_upload']['name'];
    $query="insert into imgtables (imgurl,date) values('$img',now())";
    if($sp->query($query)){
     echo "<br/>Inserted to DB also";   
    }else{
        echo "Error <br/>".$sp->error;       
    }


}
else
{
echo "There is an error,please retry or ckeck path";
}
}
?>
<form action="gallery.php" method="post" enctype="multipart/form-data">
<table width="384" border="1" align="center">
<tr>
<td width="108">Select File</td>
<td width="260"><label>
<input type="file" name="file_upload">
</label></td>
</tr>
<tr>
<td><label>
<input type="submit" name="upload" value="Upload File">
</label></td>
<td>&nbsp;</td>
</tr>
</table>
</form>
</body></html>

Read More...

Friday, July 5, 2013

My way learn MySQLI and PHP by examples

MySQL is world most used database and when its works PHP then they have no match. Learning MySQL is very is one can found thousand of tutorial on net but these are now old as MySQLI(or MySQL Advanced) next version are now on demand as implementation is easy, secure and little bit faster. In this tutorial I am going to share Uses of MySQli in your next project.

MySQLI and PHP by examples

For Connecting to database, create a PHP file name dbsettings.php with following code :

$sanjay=new mysqli('localhost','root','','mysqlifirst');
if($sanjay->connect_errno){
     echo $sanjay->connect_error;
 }

I think above line is quite easy to understand, mysqlifirst is the name of your database.

Data query :
Suppose you have a table name billings which has coloumn trans_id, amount and so on.
Create a another file name dataquery.php with following code:

require('dbsettings.php');
$query="select * from billings where trans_id='2013' ";
$sendq=$sanjay->query($query);
$rows=$sendq->fetch_assoc();
echo "Transaction ID. 2013 amount is Rs.".$rows['amount'];

This is I think a very simple example of using MySqli. If you have any doubt then comment below , I will try to explain it later.
+Sanjay Prasad 
Read More...

Wednesday, May 8, 2013

SCRA Detail Syllabus for year 2013-2014

Special Class Railway Apprentices (SCRA) - 2013-2014 

+Sanjay Prasad 

SCRA EXAMINATION -

Paper I General Ability Test 2 Hours 200
Paper II Physical Sciences 2 Hours 200
Paper III Mathematics 2 Hours 200
Total

600

General Knowledge 

For General Knowledge read books of SCHAND, UPKAR, TATA .

Constitution of India and its characteristic features:
Democracy, Secularism, Socialism, equality of opportunity and Parliamentary form of Government. Major political ideologies - Democracy, Socialism, Communism and Gandhian idea of non-violence. Indian political parties, pressure groups, public opinion and the Press, electoral system.
India’s foreign policy and non-alignment, Arms race, balance of power. World organisation - political, social, economic and cultural. Important events (including sports and cultural activities) in India and abroad during the past two years.
Broad features of Indian social system: The caste system, hierarchy, recent changes and trends. Minority social institution - marriage, family, religion and acculturation. Division of labour, co-operation, conflict and competition, Social control - reward and punishment, art, law, customs, propaganda, public opinion, agencies of social control - family, religion, State educational institutions; factors of social change -  economic, technological, demographic, cultural; the concept of revolution.
Social disorganisation in India: Casteism, communalism, corruption in public life, youth unrest, beggary, drugs, delinquency and crime, poverty and unemployment. Social planning and welfare in India, community development and labour welfare; welfare of Scheduled Castes and Backward Classes.
Money: Taxation, price, demographic trends, national income, economic growth. Private and Public Sectors; economic and non-economic factors in planning, balanced versus imbalanced growth, agricultural versus industrial development; inflation and price stabilization, problem of resource mobilisation. India’s Five Year Plans.
Geography : Solar system and the earth. Seasons, Climate, Weather, Soil - its formation, erosion. Forests and their uses. Natural calamities cyclones, floods, earthquakes, volcanic eruptions. Mountains and rivers and their role in irrigation in India. Distribution of natural resources and industries in India. Exploration of underground minerals including Oil. Conservation of natural resources with particular reference to the flora and fauna of India.
Science : Knowledge of the human body, nutrition, balanced diet, substitute foods, public health and sanitation including control of epidemics and common diseases. Environmental pollution and its control. Food adulteration, proper storage and preservation of food grains and finished products, population explosion, population control. Production of food and raw materials. Breeding of animals and plants, artificial insemination, manures and fertilizers, crop protection measures, high yielding varieties and green revolution, main cereal and cash crops of India.Evolution of life, plants and animals, heredity and environment-Genetics, cells, chromosomes, genes.

English
This is test understanding and command of the language of candidates. Use SCHAND English book.

Mathematics
Algebra
complex number
Matrices and Determinants
Probablity
Permutation and Combination
profit and loss
interest
Profression
quadratic equation

Trigonometry
Addition and subtraction formulae, multiple and sub-multiple angles. Product and factoring formulae. Inverse trigonometric functions - Domains, Ranges and Graphs. DeMoivre's theorem, expansion of Sin n0 and Cos n0 in a series of multiples of Sines and Cosines. Solution of simple trigonometric equations. Applications: Heights and Distance. 

Geometry
Rectangular Cartesian. Coordinate system, distance between two points, equation of a straight line in various forms, angle between two lines, distance of a point from a line. Transformation of axes. Pair of straight lines, general equation of second degree in x and y - condition to represent a pair of straight lines, point of intersection, angle between two lines. Equation of a circle in standard and in general form, equations of tangent and normal at a point, orthogonality of two cricles. Standard equations of parabola, ellipse and hyperbola - parametric equations, equations of tangent and normal at a point in both cartesian and parametric forms. 

Integral Calculus and Differential equations
Vectors and its applications 

Statistics 
Frequency distribution, cumulative frequency distribution - examples. Graphical representation - Histogram, frequency polygon - examples. Measure of central tendency - mean, median and mode. Variance and standard deviation - determination and comparison. Correlation and regression. 
  


Read More...

Wednesday, March 20, 2013

upload user profile image and save to data base -PHP MYSQLI

   If you are working on customized CMS or Social networking website then user profile image may be or may not be a head ache I have developed my own where we can upload and rename the image username.jpg/png/gif with size restriction to 200KB.

PHP MYSQLI Upload Image Tutorial

First design a table where database name is Sanjay.
Create a table userImage  fileds
user - username will be stored
url - url of img stored
lastUpload- when the upload was done.
create a folder upload/   where  all images will stored.
<?php
$user=$_SESSION['user'];
$db=new mysqli('localhost','root','','Sanjay');
if($db->connect_errno){
echo $db->connect_error;}
$pull="select * from userImage  where user='$user'";

$allowedExts = array("jpg", "jpeg", "gif", "png","JPG");
$extension = @end(explode(".", $_FILES["file"]["name"]));
if(isset($_POST['pupload'])){
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/JPG")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo '<div class="plus">';
    echo "Uploaded Successully";
    echo '</div>';
     
    echo"<br/><b><u>Image Details</u></b><br/>";
   
    echo "Name: " . $_FILES["file"]["name"] . "<br/>";
    echo "Type: " . $_FILES["file"]["type"] . "<br/>";
    echo "Size: " . ceil(($_FILES["file"]["size"] / 1024)) . " KB";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      unlink("upload/" . $_FILES["file"]["name"]);
      }
    else
      {
          $pic=$_FILES["file"]["name"];
            $conv=explode(".",$pic);
            $ext=$conv['1'];

      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/". $user.".".$ext);
      echo "Stored in as: " . "upload/" . $user.".".$ext;
      $url=$user.".".$ext;
   
      $query="update userImage set url='$url', lastUpload=now() where user='$user'";
      if($upl=$db->query($query)){
          echo "<br/>Saved to Database successfully";
              }
      }
    }
  }
else
  }
  echo "File Size Limit Crossed 200 KB Use Picture Size less than 200 KB";

  }
}
?>
<form action="" method="post" enctype="multipart/form-data">   
  <?php
    $res=$db->query($pull);
    $pics=$res->fetch_assoc();
    echo '<div class="imgLow">';
    echo "<img src='upload/$pics[url]' alt='profile picture' width='80' height='64'   class='doubleborder'/></div>";
   
    ?>
   
    <input type="file" name="file" />
    <input type="submit" name="pupload" class="button" value="Upload"/>
  
</form>

Hope You will understand this simple script.
Read More...

USSD base balance check on Linux using datacard

If you are Indian Data card user, having data card of micromax, beetal,huwai,zte we have always option to check your balance on windows OS as they provide software for that but what about Linux. I accept the pleasure of using that software is quite awesome but still we can check our data card balance on linux using a free app called Prepaid Manager.

Linux Prepaid Manager


First Install Prepaid Manager. Installing will not let you to use these app. You have also install a configuration file in which all settings are there called serviceproviders.xml

First Install libxml2-utils
sudo apt-get install libxml2-utils
if faile use command su instead of sudo.

open file manager in admin mode
 sudo nautilus
or sudo namo .....
whatever your file manager is
and search for serviceproviders.xml open in text editor
look for your service provider.
where to search this file
/user/share/mobile-broadband-provider-info/


First Look for your operator like Aircel, Vodafone, Relaince .....

Example of Aircel
and add before <apn></apn> tag

<balance-check>
<ussd>*125#</ussd>
</balance-check>

<balance-top-up>
     <ussd replacement="CODE">*130*CODE#</ussd>
 </balance-top-up>

Save the file and use Prepaid manager software.

Read More...

Sunday, February 3, 2013

Web Developer extension and the choice of Best Web Browser

If you are a web developer then the question is quite common which is
the best web browser for web development . In this tech arena every
browser want to take the number one tag. In this blog I am going to
share my favorite browser and why it became number one .
Mozilla Firefox is my favorite, I accept chrome has taken the market
share for being light and fast, internet explorer 10 is also doing well
but still I die for firefox. Right now I use Firefox 18 , in speed its
par with chrome and IE 10 in some cases faster, but right now we use
modern computer that has atleast 1GB of RAM and dual core CPU so you
can't see the speed difference only benchmarks can tell the difference.
Firefox uses more memory around 130MB but its not a problem.
Firefox offers net and clean interface, always welcome new technologies,
devoted towards open source and also stable and secure. Its extension
arena has everything you need and it makes you special , chrome also
supports extension and has decent store where you can download and
install extension with no restart feature but firefox interface is
awesome as firefox is feature rich compared to chrome. IE is by greedy
microsoft the company is not listening to its old customer as the
support of IE10 is limited to Windows 8 still now does not supports
multiplatform so it was ommitted from my list.

Firefox and the extension we die for :
If we are a web developer or SEO Expert then Firefox makes you job easy,
I am going to share a partial list of my favorite extension.

1. ADBLOCK PLUS
Web Designer has to surf a lot to get new ideas or inspiration but the
the annoying ads and pop ups make the job hard, adblock plus not only
block all these but gives you interface to control it.

2. Colorzilla
If you are a web designer or UI designer then you can't stop yourselve
playing with colors. This is not a color picker tool but has eyedropper
and other cool option.

3. Firebug
HTML , HTML5 , CSS , javascript wonder which kind of scripting is using
this firebug is the only solution, it give not only to view source of
website but with advance option. This is Web Designer no. one app.

4. Webrankstat
This is a SEO tool provides alexa rank, google rank,page index
,backlinks and other information while surfing.

list is going to updated soon.
Read More...