Showing posts with label programming. Show all posts
Showing posts with label programming. 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

?>

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

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>




Tuesday, December 20, 2022

Thursday, November 17, 2022

File Handling in C++ :: Dev c++ 5.4.2

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
{

string name;

cout << "What is your name? ";
cin >> name;

   ofstream out( "inputfile.txt",ios::ate );

if(out.is_open())

out << " My Name Is:  " << name << "!" << endl;

   else cout<<"Unable to Open File ";

        string line;

fstream in ("inputfile.txt");

        if(in.is_open()){

        while(getline(in,line) ){

        in>>line;

        cout<<line;
        
        }
}
        else{  cout<<"\nfile not open"; }

out.close();
return 0;
}

Tuesday, November 15, 2022

Interfaces in Java

package inhert;
public class Inhert  {
 public interface person{
         void name(String n);
         void age(int a );
         void clas(int c);
    }
   
    public static class usman implements person{
    public  void name(String n){
        System.out.println("Usman name= "+n);
    }
    public void age(int a){
        System.out.println("Usman age= "+a);
    }
    public void clas(int c){
        System.out.println("Usman class= "+c);
    }
    }
   
    public static class usama implements person{
    public void name(String n){
        System.out.println("Usman name= "+n);
    }
    public void age(int a){
        System.out.println("Usman class= "+a);
    }
    public void clas(int c){
        System.out.println("Usman class= "+c);
    }  
    }
   
  
       public static void main(String[] args){
           usama obj=new usama();
           obj.name("Usama hussain");
           obj.age(20);
           obj.clas(10);
          
           usman obj1=new usman();
           obj1.name("Usman Siddique");
           obj1.age(21);
           obj1.clas(9);
}   }
================================
An interface is a reference type in Java, it is similar to class, it is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
Along with abstract methods an interface may also contain constants, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods.
Writing an interface is similar to writing a class. But a class describes the attributes and behaviours of an object. And an interface contains behaviours that a class implements.
Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.
An interface is similar to a class in the following ways:
  • An interface can contain any number of methods.
  • An interface is written in a file with a .java extension, with the name of the interface matching the name of the file.
  • The byte code of an interface appears in a .class file.
  • Interfaces appear in packages, and their corresponding bytecode file must be in a directory structure that matches the package name.
However, an interface is different from a class in several ways, including:
  • You cannot instantiate an interface.
  • An interface does not contain any constructors.
  • All of the methods in an interface are abstract.
  • An interface cannot contain instance fields. The only fields that can appear in an interface must be declared both static and final.
  • An interface is not extended by a class; it is implemented by a class.
  • An interface can extend multiple interfaces.

Declaring Interfaces:

The interface keyword is used to declare an interface.

Friday, November 4, 2022

Wednesday, November 2, 2022

OnLine Doctor Appointment System Project in PHP - Programming seekerzZ

Read Also:  


OnLine Doctor Appointment System Project in PHP,HTML,CSS,Ajax


This is the complete PHP project on online doctor appointment system using PHP,HTML,Ajax,Javascript,CSS,Jquery and SQL .

To Download source code of Online Doctor Appointment System inbox me on Facebook.

Download From Here


https://www.facebook.com/usman.siddique.7771

OnLine Doctor Appointment System Project in PHP

Wednesday, September 28, 2016

Simple Calculator using MATLAB

How to create Simple Calculator using MATLAB - Matlab for beginners

GUI Video is below the code 


function varargout = mycaltest(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @mycaltest_OpeningFcn, ...
                   'gui_OutputFcn',  @mycaltest_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
function mycaltest_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;

guidata(hObject, handles);


function varargout = mycaltest_OutputFcn(hObject, eventdata, handles) 
varargout{1} = handles.output;


function four_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'4');
set(handles.ans,'String',str);


function one_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'1');
set(handles.ans,'String',str);

function point_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'.');
set(handles.ans,'String',str);

function seven_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'7');
set(handles.ans,'String',str);

function zero_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'0');
set(handles.ans,'String',str);

function two_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'2');
set(handles.ans,'String',str);

function five_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'5');
set(handles.ans,'String',str);

function eight_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
% it will take the value of ans (ans is our static text
str = strcat(str,'8');
%it will concatinate 8 with the privues string
set(handles.ans,'String',str);
%and it will again set the new value to ans static text 

function equal_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
%it will take the value 
str = eval(str);
%the eval function solve the string or evalutae the string
set(handles.ans1,'String',str);
%after evaluation the ans was 
      %shown in the above static text ans1.

function three_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'3');
set(handles.ans,'String',str);

function six_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'6');
set(handles.ans,'String',str);

function nine_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'9');
set(handles.ans,'String',str);

function div_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'/');
set(handles.ans,'String',str);

function add_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'+');
set(handles.ans,'String',str);

function sub_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'-');
set(handles.ans,'String',str);

function mul_Callback(hObject, eventdata, handles)
str = get(handles.ans,'String');
str = strcat(str,'*');
set(handles.ans,'String',str);

function clear_Callback(hObject, eventdata, handles)
set(handles.ans1,'String','');
set(handles.ans,'String','');







Read Also: