Friday, 7 March 2014

Secure image upload in php with random salt

This is a short tutorial for image upload with random salt (haven't included any other checking like file type/size--- but you can include it)

<?php
  //////////////////////////////////////////////////////////////////
  //////////// script created by DHRUBOJYOTI DAS ///////////////////
  /////////////////////////////////////////////////////////////////
  if(isset($_POST['Submit']))
  {
  ///// picking the image and storing in variable $image1 and creating a temporary variable $tmp_image1
  $image1=$_FILES['image1']['name'];
  $tmp_image1=$_FILES['image1']['tmp_name'];
 
  ////////////////////////////////////////////////////////////////
  ////////// Now the allowed extension type validation is done ///
  //////////by javascript function Checkfiles1() [check below]
  ///////// better practice do it again b php ///////////////////
  ///////// You can also validate the size of the image////////
  ////////////////////////////////////////////////////////////////
 
 
         ///// now creating my own salt (password fro each uploaded image)
         $password = "ABCDXYZW1234567890EFGLWKMNOPQRST";
    $string = str_shuffle($password);
         $salt=substr($string,0,8);

if(!empty($image1))
{
  $image1_name=$salt."_".$image1;
 
  //// uploading the image using move_uploaded_file function
//// replace your uploaded image folder name by images
$uploading = move_uploaded_file($tmp_image1, "images/".$image1_name);
if($uploading)
{
  echo "<font color='green'>File uploaded, now check your uploaded folder for the image throght the below link";
  echo "<br/>New file name :- ". $image1_name;
  ////// NOTE:- when inserting into database insert ($image1_name) not ($image1)
  /////// then insert it into your databse or something else
  echo "<br/>Thank You from Dhrubojyoti Das</font>";
}
else{
   echo "Something went wrong";
}
}
else{
  echo "Upload image to check the demo";
}


   }
?>
<html>
  <head>
    <title>
 Secure File Upload Script in PHP
</title>
<script>
function Checkfiles1()
{
var fup = document.getElementById('image1');
var fileName = fup.value;
var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "PNG" || ext == "png")
{

return true;
}
else
{
alert("Upload Gif or Jpg or png images only");
fup.value="";
fup.focus();
return false;
}
}
function validate(){
  var mar=true;
  var image = document.frm.image1.value;
  if(image == "")
  {
     mar = false;
alert("Select your image");
document.frm.image1.focus();
  }
 
    return mar;
 
}

</script>
  </head>
  <body>
  <h2>Secure image upload with random salt</h2>
  <form name='frm' method='post' enctype="multipart/form-data" onsubmit='return validate();'>
    Upload Image&raquo; <input type='file' name='image1' id='image1' onchange='Checkfiles1();'><br/>
    <br/r><input type='submit' name='Submit' value='Upload'>
  </form>
  <a href='images/'>Check Uploaded Image</a>
  </body>
</html>

Create  the images folder

Live Demo

Monday, 3 March 2014

Simple application to swap css sheets uisng button

<html>
    <head>
    <title>
   Css Swap
</title>
<link rel='stylesheet' id='css' type='text/css' href='default.css'>
<script>
 function swapcss(sheet)
 {
  document.getElementById('css').setAttribute('href',sheet);
 }
</script>
</head>
<body>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    <input type='button' value='Blue CSS' onclick='swapcss("blue.css");'>
<input type='button' value='Red CSS' onclick='swapcss("red.css");'>
<input type='button' value='Default CSS' onclick='swapcss("default.css");'>
</body>
</html>

Live Demo

Pop up window in javascript

<script language="javascript" type="text/javascript">

function popitup(url) {
newwindow=window.open(url,'name','height=500,width=500');
if (window.focus) {newwindow.focus()}
return false;
}


</script>
<a href="index.php" onclick="return popitup('index.php')">Link to popup</a>

Live Demo

System For Online Application Processing (SOAP) using codeigniter / javascript/jquery

Guys i am creating a online form processing system which i know most of the developers know how to do this , but still creating this tutorial for those who really want to know it in codeigniter

You can the live demo and updates at (http://php4allu.netau.net/SOAP/)

The deisgning is done and i have included minimum fields with photo and signature i you guys want anything to be added do comment and i will definetly add it..

Thank You....

Textarea Field Counting and Limiting using Javascript

<html>
<head>
<script language="javascript" type="text/javascript">
var maxAmount = 250;
function textCounter(textField, showCountField) {
    if (textField.value.length > maxAmount) {
        textField.value = textField.value.substring(0, maxAmount);
} else {
        showCountField.value = maxAmount - textField.value.length;
}
}
</script>
</head>
<body>
<form>
<textarea name="ta" rows="6" style="width:340px;" onKeyDown="textCounter(this.form.ta,this.form.countDisplay);" onKeyUp="textCounter(this.form.ta,this.form.countDisplay);"></textarea>
<br>
<input readonly type="text" name="countDisplay" size="3" maxlength="3" value="250"> Characters Remaining
</form>
</body>
</html>

Live Demo

Sunday, 2 March 2014

Simple online phonediary in CODEIGNITER

Guys this is just a simple online phone diary developed in codeigniter...with no designing this is just php and some HTML.

Don't get angry for the design...haven't included any css

I will try to make it look pretty and provide you the codes as soon as possible and will definetly add some more features and i will include JQUERY too.

You can check it out

1. First you have to register then login



Redirect After 'X' Seconds in JQUERY

<!doctype>
<html>
  <head>
     <title>Redirect in Jquery</title>

  <style>
   #timeLeft{
     color:red;
   }
  </style>
  </head>
  <body>
   <h1>You will be redirect to actual Page After <span id="timeLeft" >20</span> Seconds Thanks</h1>

   <script src='http://code.jquery.com/jquery-1.11.0.min.js'></script>
   <script>
$(document).ready(function() {
window.setInterval(function() {
var timeLeft = $("#timeLeft").html();
if(eval(timeLeft) == 0){
window.location= ("http://www.google.com");
}else{
$("#timeLeft").html(eval(timeLeft)- eval(1));
}
}, 1000);
});    
</script>
  </body>
</html>

Live Demo