Thursday, January 5, 2023

Upload file from URL to Server using cURL in PHP


This Post show how to upload data or audio files on server getting from URL and how to download that file in PC using URL.


First put URL in string like below:

$url = 'http://s.cdnpk.eu/pk-mp3/love-dose/s165352040.mp3';

To Download file in PC its a simple short-cut.using download attribute of <a> tag in HTML.

echo "<a href='".$url."' download='myfile.wav'>Download</a>";


Now convert that URL to file using curl.

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);

Now create a file on server. And open it in write mode.


  $fileName = "myfile.wav";
  $fh = fopen($fileName, 'w') or die("can't open file");


Write the file which we fetch from URL in 'myfile'. it was in $data variable.

  fwrite($fh, $data);
  fclose($fh);

Close the file that's it. Happy coding. :)


Monday, January 2, 2023

Object Oriented Programming (OOP)

OOP Programming SeekerzZ
Object Oriented Programming (OOP)
Object oriented programming OOP is a programming technique which is used by many programming languages and in this you have to use classes which are a user define data type and you create functions and attributes according to your use and then to use them you have to create an object or instance of that class so that you are able to access the attribute and operation of that class.
Advantages:
The object oriented programming have a main advantage of code reusability that you have to create a class for one time and then just have to create its instance where ever you want to use it.
The main concepts of object oriented programming are given below:
  • ·         Inheritance
  • ·         Encapsulation
  • ·         Overloading
  • ·         Polymorphism
  • ·         Abstraction

As we already discuss all of these topics in over previous posts but for now take a little review of all of them. Inheritance as the name suggests inheriting something from other. In this we have a supper and sub class hierarchy and sup classes are inherited form super classes and was able to use the functionality and attributes of super class. Many type of inheritance is there:
  • ·         Single level inheritance
  • ·         Multi-level inheritance
  • ·         Multiple inheritances
  • ·         Hybrid inheritance

For more there are other two very important concepts in inheritance which is following:
  • ·         Generalization
  • ·         Specialization

Encapsulation mean data hiding in classes we have to define the scope of every object and function by default they are all private. We have normally three scope resolution operator.
  • ·         Public
  • ·         Private
  • ·         Protected
  • ·         Sealed
  • ·         Sealed internal

Overloading provides us the y to define same thing with different meaning there are two type of overloading:
·         Function overloading
·         Operator overloading
In function overloading we have many functions with same name but different data type and in operator overloading we re-write the functionality of different operators like =, <, >, ||, $$ etc.

Polymorphism means many ways. In this we have many ways to class a function it cover the topic of function overriding.
The polymorphic classes contain two types of functions
  • ·         Virtual function
  • ·         Override functions


OOP languages:
There are many object oriented programming languages in which some are pure object oriented and some have both procedural and also object oriented way.
Java and C# are pure object oriented languages
C++, PHP, JavaScript are not pure object oriented but have functionality of it.

Constructor:
The constructor is default functionality in all object oriented languages which come with the classes whenever we create object of the class the default constructor call and execute its code first without calling it.
In C++, Java and C# constructor have the same name as class name and have no data type but in PHP we have to define constructor like this:

Function __construct( ) {  }




Example class in PHP:
<?php
class person{
            function __construct(){
                        echo "<h1>Person Information</h1>";
            }
            private function get_ID($id){
                        echo "<h3>Person ID No is :- ".$id.'</h3>';
            }          
            private function get_name($name){
                        echo "<h3>Person name is :- ".$name.'</h3>';
            }          
            private function get_mob($mob){//have private scope
                        echo "<h3>Person Mobile No is :- ".$mob.'</h3>';
            }          
            public function calle($id,$name,$mob){
                        $this->get_ID($id);
                        $this->get_name($name);
                        $this->get_mob($mob);
            }
}
                        $obj = new person();//object creation
                        $obj->calle(101,'Usman','0307-5230948');//function calling

?>

Backup and Restore in C# Windows Form Application

Read Also:  


Programming SeekerzZ

To create backup of database from C# application and then restore it again from C# application follow the steps.
First design a form like bellow:
Form Design for Backup and Restore


Browse Button of Backup Option:

FolderBrowserDialog dlg=new FolderBrowserDialog();
            if(dlg.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = dlg.SelectedPath;

            }


Backup Button Code:

string databse = con.Database.ToString();
            try
            {
                if (textBox1.Text == string.Empty)
                {
                    MessageBox.Show("Please Enter by Browseing Database Backup Location....!");
                }else
                {
                    string cmd = "BACKUP DATABASE [" + databse + "] TO DISK='" + textBox1.Text + "\\" + "database" + "-" + DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss") + ".bak'";
                    using(SqlCommand command = new SqlCommand(cmd, con))
                    {
                        if(con.State != ConnectionState.Open)
                        {
                            con.Open();

                        }
                        command.ExecuteNonQuery();
                        con.Close();
                        MessageBox.Show("Databse Backup has been Successefully Created..!");

                    }
                }
            }catch(Exception ex)
            {
                MessageBox.Show("Error\n\n" + ex);

            }



Restore button Browse code:

OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "SQL SERVER database backup files|*.bak";
            dlg.Title = "Database restore";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = dlg.FileName;

            }



Restore Button Code:

try
            {
                string database = con.Database.ToString();
                if (con.State != ConnectionState.Open)
                {
                    con.Open();
                }
                try
                {
                    string sqlStmt2 = string.Format("ALTER DATABASE [" + database + "] SET SINGLE_USER WITH ROLLBACK IMMEDIATE");
                    SqlCommand bu2 = new SqlCommand(sqlStmt2, con);
                    bu2.ExecuteNonQuery();

                    string sqlStmt3 = "USE MASTER RESTORE DATABASE [" + database + "] FROM DISK='" + textBox2.Text + "'WITH REPLACE;";
                    SqlCommand bu3 = new SqlCommand(sqlStmt3, con);
                    bu3.ExecuteNonQuery();

                    string sqlStmt4 = string.Format("ALTER DATABASE [" + database + "] SET MULTI_USER");
                    SqlCommand bu4 = new SqlCommand(sqlStmt4, con);
                    bu4.ExecuteNonQuery();

                    MessageBox.Show("Database Restoration Done Successefully");
                    con.Close();

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

            }catch(Exception ex) { }





If you are facing any problem in that program contact me with your issue :
https://www.facebook.com/usman.siddique.7771

Sunday, January 1, 2023

Saturday, December 31, 2022

How to search and find data from SQL database using PHP

In last post we learn how to delete data from sql database in this post i will show you how to find some data and verify that data from sql database using php.

So for this SQL select query is used and we select this time a user name and password to verify them. If the user name match with the name in database then this show an output that user verified.



<?php
include "conn.php";

$user = $_POST['user'];
$pass = $_POST['password'];


$sql = "select user,password from alogin where user='".$user."' and password='".$pass."';";
$result=$conn->query($sql);


if ($result->num_rows > 0) {
    echo "User Athenticate successfully";

} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>


Create-connection-with-sql-database-in-php

Thursday, December 29, 2022

Cookies in PHP

To create cookies setcookie( ) method is used:


Example:
setcookie("name","usman" ,time( ) + (86400 * 30), "/");
Syntax:
setcookie(name, value, validity time, path, domain);

To retrieve value from cookies:

Example:
echo $_COOKIE['name'];
Syntax:
$_COOKIE['cookie name'];


To discard cookies:

set cookies expiry time 1 hour back
setcookie("name","usman" ,time( ) - (3600), "/");


Download Code


index.php


<form action="#" method="POST" class="myform">
<input type="text" name="user" placeholder="Enter Your Name..." />
<input type="submit" />
</form>

<div class="myinfo">
<?php 
if(isset($_COOKIE['uid'])){
echo "<h1>Your Name is : ".$_COOKIE['uid']."</h1>";
}
?>

</div>


new.php


<?php
if(isset($_POST['user'])){
$user = $_POST['user'];
setcookie("uid",$user,time() + (86400 * 30), "/");
header("location:index.php");
}

Monday, December 26, 2022

Friday, December 23, 2022

Add or Remove Input fields Dynamically Using JQuery - HTML

Add or Remove Input fields Dynamically Using JQuery - HTML
add/remove multiple input fields in html forms


if you are looking to add and remove duplicate input fields, here’s another jQuery example below to do the task for you. This jQuery snippet adds duplicate input fields dynamically and stops when it reaches maximum.

Code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
$(document).ready(function() {
    var max_fields      = 10; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap"); //Fields wrapper
    var add_button      = $(".add_field_button"); //Add button ID
    
    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><input type="file" name="mytext[]"/><a href="#" class="remove_field">X</a></div>'); //add input box
        }
    });
    
    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
});
</script>



<div class="input_fields_wrap">
    <button class="add_field_button">Add More Fields</button>
    <div><input type="file" name="mytext[]"></div>

</div>




Thursday, December 22, 2022

Fore Ground Extraction and Back ground subtraction from video in Matlab




Gait recognition project Dataset

As i'm currently working on biometric gait recognition project so to complete that project i have to background subtraction to extract foreground from video.

i'm using CASIA data set videos for my experiments.
So background subtraction is the first thing to do in my project so when we have extracted human structure from video we easily perform our algorithms on it to identify its gait.


Matlab code for background subtraction using frame difference:

clc;              % clear command window
clear all;     % clear work space

% Reading video from computer directory
videoObject = VideoReader('001-bg-01-090.avi');

% Determine how many frames there are.
numberOfFrames = videoObject.NumberOfFrames;

% Loop through all frames
for frame = 1 : numberOfFrames

% Extract the frame from the movie structure.

img1 = read(videoObject, frame);
        img2 = read(videoObject, frame+10);

% In above we take two frame to subtract them from each other

% Subtract frames from each other
img3 =  imsubtract(img1,img2);

% Convert the subtracted result to rgb
  img4 = rgb2gray(img3);

% Apply sobel edge detection on rbg frame
  img5 = edge(img4,'Sobel');

% Use morphological approach to fill holes

d =  bwmorph(ege,'remove',1);
 e = imfill(d,'holes');

% And now save them one by one in hard-disk
        outputFolder = '\newdataset\chknew1';
       
       FileName = sprintf('img%.2d.png', frame);

outputFileName = fullfile(outputFolder, FileName);

imwrite(e, outputFileName, 'png');
        
        end


Tuesday, December 20, 2022

Thursday, December 15, 2022

How to Start a Software Company in Pakistan


Graduates coming out from Universities are usually very passionate to start a software house of their own. Once they step into the real world, pictures from the dream word start getting blurred and things start looking much more complex then what they envisioned in their dreams.

An initial thought of putting down few computers together in a nice office, giving a good name to this small setup and taking up the seat of CEO of this house, now looks like nothing more than an exercise of interior decoration. People standing outside on the road, will start rushing into this new facility to get their software ordered and we will start making big deals and will have dollars flowing all around is another aspiration that now looks like a big exaggeration.
So what?
What am I supposed to do?
You need projects to start work. Where to get from? Local market? International market? Or should you start developing a new product? How should you decide?
Project or Product?

Project:
A project is a customer specific order for developing software as per his/her specific needs. For a project to get started you need to have a customer paying for it and signing a deal with you.
Product:
Product is usually a new idea or a modification of existing product, targeting customers all around in some specific business domain and does not need any binding, deal or agreement before hand.
Should I go for Projects or should I innovate a product? That’s a challenging question and in fact draws a baseline of your business motive and is a strategic decision. How to decide? What are the factors to base my decision upon?
Here we go with some important considerations for a new entrepreneur:
Capital:
How much can you invest and for how long can you invest without worrying for ROI (Return on investment).
Let’s say I have 1 million and can invest for 2 years without running into financial crises. Will not need to withdraw single penny from my business, have other sources of income to sustain myself and so on. That looks like a relatively good condition for an innovation, but only if I can innovate something.

What should I innovate?
Should I go for a flying train? No, we are only talking about a software innovation. So what should I? Should I develop a product for NASA for tracking satellites? That would impose a big risk, what if NASA refuses to buy the product or is not interested at all. Should I go for an income tax calculator? I need too much of domain knowledge for that, would I be able to get the services of a Tax consultant to guide me on that? Tax laws are different in different countries so my solution would be country specific, most probably for Pakistani citizens. Are Pakistani citizens literate enough to go for computer based software solutions for tax calculation? Do we have any existing solutions in the market for tax calculation? Does FBR provide any such facility, if so then why would someone like to buy mine? Can I provide more user friendly and precise interface for that matter?
After doing all the needed R&D and putting down the answers for above why’s and what’s, let’s say results are positive. What next? Would it be feasible? What comes under feasibility? To calculate feasibility I will consider following ingredients:
Scope: What should precisely be the scope of this product? All kinds of taxes? Or some specific taxes like income tax, wealth tax etc.
Interfaces: What different interfaces should I provide?
  • Simple desktop utility?
  • Web based online calculator?
  • A web service for any third party vendor?
Resources: What different resources would I need? How much of human resource utilization would it take to complete this product end to end? Then office infrastructure, electricity and power backups, Internet connections and towards the end I will need marketing resources to get the product out the door.
Cost: Cost would be determined based on the scope that I define the interfaces that I choose and accordingly resources that are needed.
Feasibility comes to a point where I can say “Yes” or “NO”. Does it fall within my budget and within the defined period of investment?
If finally I get a big “YES” I will go for it and setup a small facility, hire resources and start development of the product, will do my hard and will patiently wait for the outcome. My software house is up and running.
Now let’s talk about track 2, I don’t have much capital and I’m not willing to take risk associated with my innovation. I need earlier commitments from my clients before starting the development cycle. These conditions dictate me to go for Project oriented setup.

How to start such a setup?
There are two ways to do it; either I should have some references in the market from where I could get a project OR I should go for online options, where I could try bidding for online applications and utilities from sites like “rent-a-coder” etc.
If I could be hunting my own references in the local market, I need to be aware of pros and cons associated with this approach. Being a Pakistani national I know my local market is not very much software literate and/or computer literate so opportunities in the local market for a beginner would not be very encouraging.
Secondly the paying capacity of local market is not too good so I might not get rewarded for the effort which I will put in.
Third and more important issue, our local businessmen always considered “software automation” more of a luxury than a need so they don’t opt for it that easily but now situation is changing; people are getting acquainted with the “goods” of automation specifically the efficiency it brings in.
So keeping in mind these factors associated with the local market I will see if it meets what I need from it. If that’s sounds feasibly a fine start, I can try that out and meanwhile I would also keep building my profile for freelance sites to get myself into that business as well. Sites like “rentacoder.com” give us good opportunities to establish our self online. It might not usually be big order but usually going for a bunch of small orders will get you a good start if you are really putting your hard for it.
So summarizing the discussion whether you are going product oriented or project oriented, you need to plan well and estimate the risks associated with it. Otherwise going by the wind will not get you anywhere.

Tuesday, December 13, 2022

How to Create and Destroy sessions in PHP

Sessions are used in php for saving data which is used on several pages like in cpanel we need admin id on all pages to verify him and if the session destroy the user have to login again .
in this post i use a text box and two pages text box is to enter any value and then save that value in session and check on both pages that is this session exist? and if we destroy that session the value will not shown any more.


Start session:       session_start();
Assign value to session: $_SESSION['myname']= " $username";
Destroy session: session_unset();

Download Code


First page : index.php:


<!DOCTYPE html>
<html>
<head>
<title>Session is PHP</title>
</head>
<body>

<h2>To demonstrate the concept of session put a name in text box and check the session value by clicking buttons.</h2>
<h2><a href="usman.php">Second Page</a></h2>

<form action=" " method="POST">
<p><input type="text" name="username" placeholder="Type any name here..." required></p>
<p><input type="Submit" value="Check Session value"></p>
</form>

<form action=" " method="POST">
<p><input type="Submit" value="Distroy Session" name="dstroy"></p>
</form>
<?php
session_start();

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

$_SESSION['myname']=$_POST['username'];
echo "<br><h1>Session has a value= ".$_SESSION['myname']."</h1>";
}

if(isset($_SESSION['myname'])){
if(!isset($_POST['username']))
echo "<br><h1>Session has a value= ".$_SESSION['myname']."</h1>";
}

if(!isset($_SESSION['myname'])){
echo "<br><h1>Session not set...yet.!!</h1>";
}

if(isset($_POST['dstroy'])){
session_unset();
header("location:index1.php");
}

?>

<p>Check Session is user when user login in </p>
<p>Distroy session is used when user logout</p>
</body>

</html>



Second page: usman.php


<?php

session_start();
if(isset($_SESSION['myname'])){
 echo "<br><h1>Session has a value= ".$_SESSION['myname']."</h1>";
}

else{
echo "<br><h1>Session not set...yet.!!</h1>";
}


?>

<h2><a href="index1.php">First Page</a></h2>
<p>Check Session is user when user login in </p>

<p>Distroy session is used when user logout</p>


Saturday, December 10, 2022

Up-Date data in SQL database using Php

In last two posts i discus how to create connection and how to insert data in data base using php.

Insert-data-in-SQL-database-using-PHP


Create-connection-with-sql-database-in-php

In this post i will show you how to update data in SQL database table using php.
so for this first we need database connection which we create in first post so just include that file and then code for update query


Thursday, December 8, 2022

Insert Data in sql database using php

How to insert data in sql database using PHP?
In my previews post i show how to create connection with database using php and now in this post i show how to add data in database using php.

so for this first we need a table in database say login which have two columns user and password and we try to insert data in them so we use html form to get data from user and by using post method we get that data in php and then insert it in sql using sql query.


<?php
include "conn.php";

$a=$_POST['name'];
$b=$_POST['password'];

$sql = "INSERT INTO login (usar,pasword)
VALUES ('".$a."','".$b."'');";



if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";

} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>


we include the conn.php file here because we create connection in this file to learn how to create connection see create-connection-with-sql-database-in.html

Sunday, December 4, 2022

Simple Login Form Using HTML and CSS

Beautiful login form using html and css with black background .Free html css code for login form for your website login panel with beautiful colors.

Download Full Code From Here


HTML Code:
<div class="login"><form>
<h1 style="text-align:center;color:wheat;">Welcome</h1>
<input type="text" placeholder="Email">
<input type="Password" placeholder="Password">
<input type="submit" value="Login">
<a href="#" >Forget Password?</a>
</form></div>

<h2 style="color:yellow;bottom:0;text-align:center;">
Simple Login Form Using HTML CSS By Usman Siddique</h2>



CSS Code:

<style>
body{background-color:#000d33;}
.login{width: 35%;margin: 15% auto;}
a,input{display: block;padding: 2%;width: 80%;margin: 25px auto;box-shadow: 13px 13px 300px whitesmoke;border-radius: 10px;font-weight:  bold; }
input[type=submit]{background-color: orange;border: 0px;}
a{text-align: center;text-decoration: none;border-top: 1px solid white;width: 75%;border-radius: 0px;border-bottom: 1px solid wheat; }

</style>


Saturday, December 3, 2022

Thursday, December 1, 2022

Simple Portfolio example for web sites using HTML and CSS



Usman Siddique

Programming SeekerzzZ

Taxila,Cantt
PcpHunt

Experience

Have three year of experinece

Areas of Experience

PHP, HTML, C#, ASP>Net, C++, JS

Code here :

<html>
<style>
.behind h3{text-align: center;margin: 10px;}
.img1{height: 40%;width:40%;border-radius:100%;margin-left:27%;margin-top:10%;box-shadow:5px 3px 145px blue;}
.front h3,p{text-align:center;padding: 10px;}
h3,p{padding:0px;margin:0px;}
.main{margin:auto;width:20%;box-shadow: 2px 2px 25px green;}
.behind,.front{width: 100%;height: 40%;}
.behind{display: none;border: 2px solid skyblue;background-color: lightblue;}
.main:hover .front{display: none;}
.main:hover .behind{display: block;}

</style>
<div class="main">
<div class="front"> <img class="img1" src="b.jpg"><br><h3>Usman Siddique</h3><p>Programming SeekerzzZ</p><br><img src="as.jpg" >Taxila,Cantt<br><img src="as.jpg">PcpHunt</div>



<div class="behind"><h3>Experience</h3>Have three year of experinece<h3>Areas of Experience</h3>PHP, HTML, C#, ASP>Net, C++, JS</div>

</div>

Monday, November 28, 2022

Simple Count Down using Java-script - - HTML,CSS

Simple counter in java script 

Time Counter


-------------------------------------------

HTML Code:



<div class="counter">
<h4>Time Counter</h4>

<p id="demo"></p></div>



JavaScript Code:




<script type="text/javascript">
var dely=15;
var i = 0, howManyTimes = 16;
function f() {
if(dely>9){document.getElementById("demo").innerHTML=("00:"+dely--);}
else{document.getElementById("demo").innerHTML=("00:0"+dely--);}
i++;
    if( i < howManyTimes ){
        setTimeout( f, 1000 );
    }else{}
}
f();

</script>



CSS Code:

Thursday, November 24, 2022

Simple Search Box Example HTML 5 ,CSS 3

Many Frinds Ask me about a think how to put button inside a textbox so thats we see on many site search box like that .. thats not actully a button inside textbox its a div which contain both button and textbox and we hide their actul color :
Here is a simple example :


<div class="wrapper">
    <input type="text" />
    <button>GO</button>
</div>
<h3>Simple search Box Example</h3>
<h2>Programming Seekerz</h2>


<style>
.wrapper {
    border:1px solid #000;
    display:inline-block;
    position:relative;

}

input,
button {
    background-color:transparent;
    border:0;
}

button {
    position:absolute;
    right:0;
    top:0;
}

input {
    padding-right:30px; /* button padding */
}
</style>