Showing posts with label Interesting Programs. Show all posts
Showing posts with label Interesting Programs. Show all posts

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

?>

Sunday, January 1, 2023

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