Thursday, April 28, 2016

jQuery- Count characters in textarea

Topic: 1.Character Counting Remaining on textarea using jQuery.
Topic: 2. jQuery- Count characters in textarea
Topic: 3. How can I count characters in textarea on onkeyup() event using jQuery?
 
We can find above topics solutions in below code.

 
<!DOCTYPE html>
<html>
  <head>
    <script src="http://code.jquery.com/jquery-1.5.js"></script>
    <script>
      function countChar(val) {
        var len = val.value.length;
        if (len >= 500) {
          val.value = val.value.substring(0, 500);
        } else {
          $('#charNum').text(500 - len);
        }
      };
    </script>
  </head>

  <body>
    <textarea id="field" onkeyup="countChar(this)"></textarea>
    <div id="charNum"></div>
  </body>

</html>

Wednesday, April 27, 2016

Magento- upload multiple files with Varien_File_Uploader

Topic 1:  upload  file with Varien_File_Uploader .
Topic 2:  How can I upload image using Varien_File_Uploader in magento?
Topic 3:  Upload image using default magento function.

We can find above topic's solution in below code.
 

 if(isset($_FILES['add_image']['name']) && $_FILES['add_image']['name'] != '') {
            try {
                /* Starting upload */
                $uploader = new Varien_File_Uploader('add_image');

                // Any extention would work
                $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
                $uploader->setAllowRenameFiles(false);

                $uploader->setFilesDispersion(true);

                // We set media as the upload dir
                $path = Mage::getBaseDir('media') . DS . 'projectphoto' . DS . 'image' . DS;
                $uploader->save($path, $_FILES['add_image']['name'] );
                echo '-->'.$img_name = $uploader->getUploadedFileName();
            } catch (Exception $e) {

            }
        }

Thursday, April 21, 2016

jQuery- get multiple image's file name on browse image

Topic: 1.jQuery- get multiple image's file name on browse image
Topic: 2. How can I get file's name on browse the image?
  
We can find above topics solutions in below code.


<input type="file" id="inputFile" name="award_images[]" multiple />

<script>
jQuery("#inputFile").change(function (event) {
   var files = event.target.files;
    for(var i=0; i < files.length; i++) {
        var f = files[i];
        alert(f.name);
    }
});
</script>

magento- uplaod mupltile images using Varien_File_Uploader(

Topic 1:  upload multiple files with Varien_File_Uploader .
Topic 2:  How can I upload multiple images using Varien_File_Uploader in magento?
Topic 3:  Upload multiple images using default magento function.


We can find above topic's solution in below code.

<?php
if(isset($_FILES['award_images']) and $_FILES['award_images']['name'][0] != ''){
                 
                    $extension=array("jpeg","jpg","png","gif");
                        foreach($_FILES["award_images"]["tmp_name"] as $key=>$tmp_name)
                        {
                           
                                $uploader = new Varien_File_Uploader(
                                        array(
                                    'name' => $_FILES['award_images']['name'][$key],
                                    'type' => $_FILES['award_images']['type'][$key],
                                    'tmp_name' => $_FILES['award_images']['tmp_name'][$key],
                                    'error' => $_FILES['award_images']['error'][$key],
                                    'size' => $_FILES['award_images']['size'][$key]
                                        )
                                );
                               
                                $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); // or pdf or anything
                                $uploader->setAllowRenameFiles(false);
                                $uploader->setFilesDispersion(false);
                                $imgname= $file_name;        
                                $path = Mage::getBaseDir('media') . DS . 'awardimage/image/';
                                $img = $uploader->save($path, $_FILES['award_images']['name'][$key]);
                               
                            
       
                        }
                  
                 }
?>