Sunday, November 20, 2016

Image Upload with preview

HTML SCRIPT

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Attached Prescription</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="../bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#images').on('change',function(){
$('#multiple_upload_form').ajaxForm({
target:'#images_preview',
beforeSubmit:function(e){
$('.uploading').show();
},
success:function(e){
$('.uploading').hide();
},
error:function(e){
}
}).submit();
});
});
</script>
</head>
<body style="">
<div style="margin-left:80px;">
<div class="upload_div">
    <form method="post" name="multiple_upload_form" id="multiple_upload_form" enctype="multipart/form-data" action="upload.php">
    <input type="hidden" name="image_form_submit" value="1" />
<div style="padding:20px;"></div>
        <input type="file" name="images[]" id="images" multiple class="btn btn-success "  style="margin-top:30">
        <div class="uploading none">
            <label>&nbsp;</label>
            <img src="uploading.gif"/>
        </div>
    </form>
<div class="gallery" id="images_preview" ></div>
<input type="button" onclick="SetAttachement()" value="Attached" class="btn btn-success " style="margin-top:20px">
    </div>
</div>
<script type="text/javascript">
function SetAttachement() {
if (window.opener != null && !window.opener.closed) {
var attachement = window.opener.document.getElementById("imgurl");
var attachement1 = window.opener.document.getElementById("pimgurl");
attachement.value = document.getElementById("cimgurl").value;
attachement1.value = document.getElementById("cimgurl").value;
}
window.close();
alert("Successfully attached.");
}
</script>
</body>
</html>



PHP SCRIPT


<?php
if($_POST['image_form_submit'] == 1)
{
$site_add ="https://store.nostlgc.com/catalog/view/theme/journal2/template/product/Prescription/UploadImage/";
$images_arr = array();
foreach($_FILES['images']['name'] as $key=>$val){
$image_name = $_FILES['images']['name'][$key];
$tmp_name = $_FILES['images']['tmp_name'][$key];
$size = $_FILES['images']['size'][$key];
$type = $_FILES['images']['type'][$key];
$error = $_FILES['images']['error'][$key];
$target_dir = "uploads/"; //Image location that are uploaded
$target_file = $target_dir.$_FILES['images']['name'][$key];
if(move_uploaded_file($_FILES['images']['tmp_name'][$key],$target_file)){
$images_arr[] = $target_file;
}
}
//Generate images view
if(!empty($images_arr)){ $count=0;
foreach($images_arr as $image_src){ $count++?>
<ul class="reorder_ul reorder-photos-list">
<input type="hidden" id="cimgurl" name="cimgurl" value="<?php echo $site_add . $image_src; ?>" >
            <li id="image_li_<?php echo $count; ?>" class="ui-sortable-handle">
                <a href="javascript:void(0);" style="float:none;" class="image_link"><img src="<?php echo $image_src; ?>" alt=""></a>
                </li>
          </ul>

<?php }
}
}
?>

Monday, October 24, 2016

Form Data Submission using JQUERY and AJAX

<script>
$(function(){
    $('#submitinfo').on('submit', function(e){
        e.preventDefault();
        $.ajax({
            url: "https://localhost/submit.php",
            type: 'POST', //or POST
            data: $('#submitinfo').serialize(),
            success: function(data){
                 alert('successfully submitted');
$('#submitinfo').hide();
            }
        });
    });
});
</script>

<form id="submitinfo">
<table>
<thead>
<h4 id="review-title">Customer information</h4>
</thead>
<tr>
<label class="control-label" for="input-name">Complete Name</label>
<input type="text" name="name" value="" id="input-name" class="form-control" required>
</tr>
<tr>
<label class="control-label" for="input-name">Phone Number</label>
<input type="text" name="guest_
</tr>
<tr>
<label class="control-label" for="input-name">Email Address</label>
<input type="text" name="email" value="" id="input-name" class="form-control" required>
</tr>
</table>
   <div class="modal-footer" STYLE="margin-top:30%;" >
       <button name="btn_submit" id="btn_submit" type="submit" class="btn btn-success">Submit</button>
   </div>
</form>

Sunday, May 29, 2016

Exporting & Importing App Pools and Websites configuration between multiple IIS instances

Using IIS server in a Cluster, Server Farm or other Load Balanced Environment will take a lot of work to setup, transferring a site from old IIS server to a new IIS server can encounter different issue in the .net framework and etc. When upgrading IIS7 (Windows Server 2008) TO IIS 8 (Windows Server 2012 R2).

appcmd is a commandline utility who can export the entire IIS Website and App. pools configuration in XML format and also import the xml into another IIS instance.

Export the Application Pools Using appcmd Command line

%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml

This command line will export all your application pools including the default in your webserver. Therefore you need to edit your appools.xml and remove the following contents that you do'nt need to import.
· DefaultAppPool
· Classic .NET AppPool
· SecurityTokenServiceApplicationPool
· .NET v2.0
· .NET v2.0 Classic
· .NET v4.5
· .NET v4.5 Classic
Import the Application Pools Using appcmd Command line
Copy the appools.xml file to your webserver and run this following command line. after that All the AppPools in the xml will be created on your second IIS server.

%windir%\system32\inetsrv\appcmd list apppool /config /xml > c:\apppools.xml

Export All Website Using appcmd Command line

%windir%\system32\inetsrv\appcmd list site /config /xml > c:\websites.xml

This command line will export all website on you IIS Server, after exporting you need to edit the websites.xml and remove the Default Website as well as any other website you don't want to export to you new IIS Server or already exist on the target IIS instance, otherwise the import command line won't work

Import All Website Using appcmd Command line
Just like you did with the App Pools file, copy the websites.xml file to your webserver and run this following command line. after that All the website in the xml file will be created on your target IIS server.

%windir%\system32\inetsrv\appcmd add site /in < c:\websites.xml



Monday, May 23, 2016

Zip File Upploader and Extracting using PHP Script

<?php

if($_FILES["fileToUpload"]["name"]) {
    $file = $_FILES["fileToUpload"];
    $filename = $file["name"];
    $tmp_name = $file["tmp_name"];
    $type = $file["type"];
   
    $name = explode(".", $filename);
    $accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');

    if(in_array($type,$accepted_types)) {
        $okay = true;
    }
   
    $continue = strtolower($name[1]) == 'zip' ? true : false;

    if(!$continue) {
        $message = "The file is not .zip file. Please try again.";
    }


        $ran = $name[0]."-".time()."-".rand(1,time());
        $targetdir = "files/".$ran;
        $targetzip = "files/".$ran.".zip";

    if(move_uploaded_file($tmp_name, $targetzip)) {
     
        $zip = new ZipArchive();
        $x = $zip->open($targetzip);
        if ($x === true) {
            $zip->extractTo($targetdir);
            $zip->close();
   
            unlink($targetzip);
        }
        $message = " <strong>{$ran}.zip</strong> file was uploaded and extracted.";

    } else {  
        $message = "Error!Uploaded file. Please try again.";
    }
}
echo $message;

?>