Monday, 26 December 2016

Jquery character and Message count textarea




JS

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#messageValue").keyup(function(){
//$("#count").text($(this).val().length);
var wordCount = $(this).val().length;
var messagePart = document.getElementById('message_part');
$("#characterCount").text(wordCount);
//alert(wordCount);
if (wordCount > 159) {
var z = wordCount / 160;
z = Math.floor(z);
z = z + 1; 
} else {
var z = 1;
}
messagePart.innerHTML = z;
});
});
</script>


HTML

<textarea name="message" id="messageValue" rows="10" placeholder="Message" required></textarea>
<div><span id="characterCount" style="color:#F00;">0</span> Characters in text Box. 
Send this Message in <span id="message_part" style="color:#F00;">1</span> Part                          
Jquery character and Message count textarea



javascript Jquery character count textarea



HTML

<textarea id="textarea" rows="8" cols="30" maxlength="99" ></textarea>
<div id="textarea_feedback"></div>

JS

$(document).ready(function() {
    var text_max = 99;
    $('#textarea_feedback').html(text_max + ' characters remaining');

    $('#textarea').keyup(function() {
        var text_length = $('#textarea').val().length;
        var text_remaining = text_max - text_length;

        $('#textarea_feedback').html(text_remaining + ' characters remaining');
    });
});

javascript character count textarea

Thursday, 22 December 2016

Multiple File Upload with PHP



HTML

<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>Multiple File Ppload with PHP</title>
</head>

<body>
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" id="file" name="files[]" multiple="multiple" accept="image/*" />
        <input type="submit" value="Upload!" /> </form>
</body>

</html>

PHP CODE

$valid_formats = array("jpg", "png", "gif", "zip", "bmp");
$max_file_size = 1024*100; //100 kb
$path = "uploads/"; // Upload directory
$count = 0;

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to exeicute all files
foreach ($_FILES['files']['name'] as $f => $name) {     
   if ($_FILES['files']['error'][$f] == 4) {
       continue; // Skip file if any error found
   }       
   if ($_FILES['files']['error'][$f] == 0) {           
       if ($_FILES['files']['size'][$f] > $max_file_size) {
           $message[] = "$name is too large!.";
           continue; // Skip large files
       }
elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
       else{ // No error found! Move uploaded files 
           if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
           $count++; // Number of successfully uploaded file
       }
   }
}
}


Multiple File Upload with PHP