Saturday 11 November 2017

Difference between input type hidden and style display none


Difference between input type hidden and style display none

1. <input type="hidden">  won't trigger input validation, auto completion, and other user interaction related events. It's designed to save raw data, without user's direct input.

Eg. a <input type="hidden">  

won't auto complete it self, or preserve the inputted data before refreshing a page, or prevent the form from being submitted for a failed type validation can't even be seen.

 2.<input type="text" style="display:none">
 is hidden element in the page, but you can give all validations in this.

3. But a  
<input type="text" style="visibility: hidden;"/ >

is different from these two described above, it does take space in the DOM, whether the above will not take any.
It is visually hidden, are still going to be considered as a user interaction component. And on some devices enabled visual aid, it will serve as not hidden, and cannot provide the consistency you expected. That's why it's not preferred to do so.

Monday 17 April 2017

Difference between self and $this in php

$this
Use $this to refer to the current object. 

self::
Use self to refer to the current class. 


In other words, use  $this->member for non-static members, 
use self::$member for static members.

How we can Access abstract class function in child class

 Access abstract class function in child class

<?php

abstract class parentTest
{
abstract protected function f1();
abstract public function f2();
public function f4()
{
echo "Parent";
}
}

// Child class ...........
class childTest extends parentTest
{
public function f1()
{
echo "f1";
//body of your function
}
public function f2()
{
parent::f4();//Accessing parent class function
echo ":f2";
//body of your function
}
protected function f3()
{
echo "f3";
        //body of your function
}
}
$a = new childTest();
$a->f2();//Parent:f2

?>

Overloading and Overriding in php

Overloading in PHP


class overloading {
    public $methodName;
    public function __construct($argu) {
        $this->methodName = $argu;
    }
    public function __call($methodname, $agru) {
         if($methodname == 'sum2') {

          if(count($agru) == 2) {
              $this->sum($agru[0], $agru[1]);
          }
          if(count($agrument) == 3) {

              echo $this->sum1($agru[0], $agru[1], $agru[2]);
          }
        }
    }
    public function sum($a, $b) {
        return $a + $b;
    }
    public function sum1($a,$b,$c) {

        return $a + $b + $c;
    }
}
$object = new overloading('Sum');
echo $object->sum2(1,2,3);//6

Overriding in PHP

<?php

class A {
   function print() {
      return "print::1";
   }
}

class B extends A {
   function print() {
      return "print::2";
   }
}

$foo = new A;
$bar = new B;
echo($foo->print()); //"print::1"
echo($bar->print()); //"print::2"
?>

Tuesday 11 April 2017

How to load jQuery Library when CDN fails

How to load jQuery Library when CDN fails
It is a good approach to always use CDN but sometimes what if the CDN is down (rare possibility though) but you never know in this world as anything can happen. Server may have reason to get down, so we need to be take care of these problems.

Below given jQuery code checks whether jQuery is loaded from Google CDN or not, if not then it references the jQuery.js file from your folder.


if (typeof jQuery == 'undefined'{
console.log(" Jquery undefined");
  document.write(unescape("%3Cscript src='MyScripts/jquery.1.12.1.min.js' type='text/javascript'%3E%3C/script%3E"));
}



It first loads the jQuery from Google CDN and then check the jQuery object. If jQuery is not loaded successfully then it will references the jQuery.js file from hard drive location. In this example, the jQuery.js is loaded from Scripts folder.

Thursday 6 October 2016

How to download audio file from any server in php

Download audio file from server using Curl

After so many efforts and time I have downloaded all the audio file from my server to local diectory.

Here is the code that I have written.I have a CSV file which contains all the links of the audio files

"http://www.dsdsdsdsd--/download/324324","2016-10-06"
"http:///www.dsdsdsdsd--/download/32qww4324","2016-10-06"

 .............................

...............................

Curl must me installed in your system.


First You need to parse this file to get the Url's then hit the URL using curl

<?php 

$file       = '/var/www/html/test/results.csv';
$fileData   = fopen($file,'r');
while($row = fgets($fileData)){ 

    $tempUrl         =  explode(",",$row);
    $tempFileNameArr = explode("/",$tempUrl[0]);
    //print_r($tempFileNameArr);
    $remoteFileName  = rtrim($tempFileNameArr[6],'"');
    
    $ch   = curl_init();
    echo $tempUrl[0];
    $url = trim($tempUrl[0],'"');
    $url = rtrim($url, '/\\');
    echo "FInal ULR::$url";
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    echo "Strlen is::".strlen(trim($tempUrl[0]));
    $fp = fopen($remoteFileName.'.mp3', 'w');

    // Set CURL to write to disk
    curl_setopt($ch, CURLOPT_FILE, $fp);

    // Execute download
    curl_exec ($ch);
    echo "status::".$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $output = '';
    if (curl_error($ch)){
        $output .= "\n". curl_error($ch);
    }
    echo $output;
    //echo "output".$output;
    curl_close ($ch);

    fclose($fp);

}
fclose($fileData);

?>



Problem faced:

1.Status 0 from curl request 

References:

1. https://curl.haxx.se/docs/manpage.html#-L

2.http://stackoverflow.com/questions/2392677/best-way-to-remove-trailing-slashes-in-urls-with-php


2. Status 301

Add this line will solve your problem


curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

http://stackoverflow.com/questions/21233771/php-curl-function-301-error


CURLOPT_FOLLOWLOCATION cannot be activated when 

in safe_mode or an open_basedir is set



Solution 1:

Set safe_mode = Off in your php.ini file (it's usually 
in /etc/ on the server). If that's already off, then look around for 
the open_basedir stuff in the php.ini file and comment that 
line (#open_basedir...). Restart apache server.




Tuesday 6 September 2016

HOW TO CONFIGURE GIT COMMIT CREDENTIALS



You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author