বুধবার, ৩১ ডিসেম্বর, ২০১৪

File Upload by angular and php


We are going to upload file by angular and php

Step 1: First of all we need to add a few file in our header section.


<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/danialfarid-angular-file-upload/1.6.1/angular-file-upload-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/danialfarid-angular-file-upload/1.6.1/angular-file-upload.js"></script>


Step 2: and then add the following html in your body section.


<div ng-app="_cars_app">
  <div ng-controller="MyCtrl">
  <input type="text" ng-model="test"/>
<input type="file" ng-model="fname" name="image" id="image" ng-file-select="onFileSelect($files)">
   <br/>
 <span class="errorMsg">---{{ message }}----</span>
</div>
</div>

Step 3: Write js code before the html. Basically this code is used for upload request

<script>
//inject angular file upload directives and service.
//inject angular file upload directives and service.
angular.module('_cars_app', ['angularFileUpload']);

var MyCtrl = ['$scope', '$upload', function($scope, $upload) {
  $scope.onFileSelect = function($files) {
   var file = $files[0];

   console.log(file.type.indexOf('image'));

   if (file.type.indexOf('image') == -1) {
        $scope.error = 'image extension not allowed, please choose a JPEG or PNG file.'          
   }
   if (file.size > 2097152){
        $scope.error ='File size cannot exceed 2 MB';
   }
 
   //console.log($scope.fname);
   $scope.upload = $upload.upload({
       url: "upload.php",
       data: {fname: $scope.fname},
       method: 'POST',
       file: file
     }).success(function(data, status, headers, config) {
        $scope.message = data;
     }).error(function(data, status) {
           $scope.message = data;
     });
    }
}];
</script>


Step 4:
Create a file which called upload.php and peste the following code inside the file.

<?php

$fname = $_POST["fname"];

    if(isset($_FILES['file'])){
        //The error validation could be done on the javascript client side.
        $errors= array();      
        $file_name = time(). $_FILES['file']['name'];
        print time(). $file_name;
        $file_size =$_FILES['file']['size'];
        $file_tmp =$_FILES['file']['tmp_name'];
        $file_type=$_FILES['file']['type'];
        $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
        $extensions = array("jpeg","jpg","png");      
        if(in_array($file_ext,$extensions )=== false){
         $errors[]="file extension not allowed, please choose a JPEG or PNG file.";
        }
        if($file_size > 2097152){
        $errors[]='File size cannot exceed 2 MB';
        }            
        if(empty($errors)==true){
            move_uploaded_file($file_tmp,"images/".$file_name);
           // echo $fname . " uploaded file: " . "images/" . $file_name;
        }else{
            print_r($errors);
        }
    }


?>


Step -5: Let's review your code.

<!DOCTYPE html>
<html>

<head>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular-route.min.js"></script>
<script src="js/angular-file-upload-shim.min.js"></script>
<script src="js/angular-file-upload.js"></script>
<script>
//inject angular file upload directives and service.
//inject angular file upload directives and service.
angular.module('_cars_app', ['angularFileUpload']);

var MyCtrl = ['$scope', '$upload', function($scope, $upload) {
  $scope.onFileSelect = function($files) {
   var file = $files[0];

   console.log(file.type.indexOf('image'));

   if (file.type.indexOf('image') == -1) {
        $scope.error = 'image extension not allowed, please choose a JPEG or PNG file.'          
   }
   if (file.size > 2097152){
        $scope.error ='File size cannot exceed 2 MB';
   }
   alert(23);
   //console.log($scope.fname);
   $scope.upload = $upload.upload({
       url: "upload.php",
       data: {fname: $scope.fname},
       method: 'POST',
       file: file
     }).success(function(data, status, headers, config) {
        $scope.message = data;
     }).error(function(data, status) {
           $scope.message = data;
     });
    }
}];
</script>
</head>
<body>
<div ng-app="_cars_app">
  <div ng-controller="MyCtrl">
  <input type="text" ng-model="test"/>
<input type="file" ng-model="fname" name="image" id="image" ng-file-select="onFileSelect($files)">
   <br/>
 <span class="errorMsg">---{{ message }}----</span>
</div>
</div>
</body>
</html>



That's it. Thanks for reading this code.


মঙ্গলবার, ১৮ নভেম্বর, ২০১৪

Install skype on ubuntu 14.04 64bit

Hi everyone. Today we'r going to install skype on ubuntu14.04 64bit. Just follow the step below to install.

Step 1: Remove previous version.

sudo apt-get remove skype skype-bin:i386 skype:i386
sudo apt-get install sni-qt:i386

It is Important if you installed older version of Skype on your Ubuntu, Clear the old Skype folder before installing latest version. Then clear that by using:

rm -rf ~/.Skype

Step 2: Preparing to Installing Skype.

  • Users of 64-bit Ubuntu, should enable MultiArch if it isn't already enabled by running the command
    sudo dpkg --add-architecture i386
    
  • Update repositories and "updates" list:
    sudo apt-get update
    sudo apt-get install gdebi #(read Why you need to install gdebi...)
    

Step 3: Installing Skype

wget download.skype.com/linux/skype-ubuntu-precise_4.3.0.37-1_i386.deb
sudo gdebi skype-ubuntu-precise_4.3.0.37-1_i386.deb

Step 4: Link skype to user bin

LD_LIBRARY_PATH=/usr/lib/i386-linux-gnu/ /usr/bin/skype


That's it. Enjoy your  skype. Thanks for your patient reading.

Why does Skype not start when I click the Skype Launcher?

If you installed skype on ubuntu, but can't be able to open it. Then you'r in right place to fix this problem. Just open your terminal and play this following command.


LD_LIBRARY_PATH=/usr/lib/i386-linux-gnu/ /usr/bin/skype


That's it. 

বুধবার, ১৭ সেপ্টেম্বর, ২০১৪

Customize 404, 500, 503 error page on symfony

All of the error templates live inside TwigBundle. To override the templates, we simply rely on the standard method for overriding templates that live inside a bundle.

All of the error template you'll find on TwigBundle. To see the full list of default error templates, see the Resources/views/Exception directory of the TwigBundle. In a standard Symfony2 installation, the TwigBundle can be found at vendor/symfony/src/Symfony/Bundle/TwigBundle. Often, the easiest way to customize an error page is to copy it from the TwigBundle into app/Resources/TwigBundle/views/Exception and then modify it.


In your error500.html.twig page

<h1>Oops, you've found a dead link.</h1>
<h2>{{ exception.message|nl2br|format_file_from_text }}</h2>

Custom templates for 403, 404 and 500 errors, so i created error.html.twig (parent template) and error403.html.twigerror404.html.twig and error500.html.twig that extends from 'TwigBundle:Exception:error.html.twig' (overridden by your custom parent template).

শনিবার, ১৭ মে, ২০১৪

Take screenshot by canvas

We are going to take a screenshot from our current page by html5 canvas. So why we are waiting for. Let's start

1. At first we have to create our current page. Crate index.html page and copy the below stuff and paste it.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
  <head>
    <title> Take screenshot by html5 canvas</title>
  </head>
  <body>
    <p>This is a simple page. which we'll take a screenshot from it.</p>
  </body>
</html>

2. You have to download html2canvas.js file and include it into your head section

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
  <head>
    <title> Take screenshot by html5 canvas</title>
    <script type="text/javascript" src="html2canvas.js"></script>
  </head>
  <body>
    <p>This is a simple page. which we'll take a screenshot from it.</p>
  </body>
</html>

3. and finally add the below script.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
  <head>
    <title> Take screenshot by html5 canvas</title>
    <script type="text/javascript" src="html2canvas.js"></script>
    <script type="text/javascript">
        html2canvas(document.body, {
            onrendered: function(canvas) {
var imgString = canvas.toDataURL("image/png");
                 window.open(imgString);
            }
        });
    </script>
  </head>
  <body>
    <p>This is a simple page. which we'll take a screenshot from it.</p>
  </body>
</html>


Now you are free to browse and enjoy.

শনিবার, ১৫ মার্চ, ২০১৪

php to adv


preserveWhiteSpace = false; $doc = $xmlDoc->createProcessingInstruction("ADF", '"VERSION="1.0"'); $xmlDoc->appendChild($doc); //Create adf element $adf = $xmlDoc->createElement('adf'); $adf = $xmlDoc->appendChild($adf); $customer = $xmlDoc->createElement('customer'); $customer = $xmlDoc->appendChild($customer); $contact = $xmlDoc->createElement('contact'); $contact = $xmlDoc->appendChild($contact); //Name part 1 $nameEle = $xmlDoc->createElement('name'); $nameattr = $xmlDoc->createAttribute('part'); $nameattrVal = $xmlDoc->createTextNode('first'); $nameattr->appendChild($nameattrVal); $nameEle->appendChild($nameattr); $name1 = $xmlDoc->appendChild($nameEle); $nameNode = $contact->appendChild($name1); $nameTextNode = $xmlDoc->createTextNode('Masum'); $nameNode->appendChild($nameTextNode); //Name part 2 $nameEle2 = $xmlDoc->createElement('name'); $name2attr = $xmlDoc->createAttribute('part'); $name2attrVal = $xmlDoc->createTextNode('last'); $name2attr->appendChild($name2attrVal); $nameEle2->appendChild($name2attr); $name2 = $xmlDoc->appendChild($nameEle2); $name2Node = $contact->appendChild($name2); $name2TextNode = $xmlDoc->createTextNode('Billah'); $name2Node->appendChild($name2TextNode); //Email $email = $xmlDoc->createElement('email'); $email = $xmlDoc->appendChild($email); $emailNode = $contact->appendChild($email); $emailTextNode = $xmlDoc->createTextNode('email@gmail.com'); $emailNode->appendChild($emailTextNode); //Phone $phone = $xmlDoc->createElement('phone'); $phone = $xmlDoc->appendChild($phone); $phoneNode = $contact->appendChild($phone); $phoneTextNode = $xmlDoc->createTextNode('019733'); $phoneNode->appendChild($phoneTextNode); //Contact & Customer $contactNode = $customer->appendChild($contact); $adfNode = $adf->appendChild($customer); //Output $xmlDoc->formatOutput = true; echo "". $xmlDoc->saveXML() .""; $xml->save("mybooks.xml") or die("Error"); ?>