Tuesday 30 September 2014

Update or save file using ajax request

How to upload an image using "ajax reguest" in PHP

Note: We need to pass atleast one parameter otherthan file upload control. Then only the ajax file upload will work properly in PHP.

/*================Ajax request from HTML Page=================*/
function SaveImage(vId){
debugger;
   var vCategory=$("#hdnCategory").val();
   //Creating object for form data to collect control's data from HTML page
                   var m_data = new FormData();
   m_data.append('desc', $("#txtDescription").val());
                  //collecting data from file upload control
   m_data.append('file_attach', $('input[name=file_attach]')[0].files[0]);
m_data.append('rowId',vId);
m_data.append('category',vCategory);
            $.ajax({
              url: 'contact_me.php',  //PHP page url
              data: m_data,
              processData: false,
              contentType: false,
              type: 'POST',
              dataType:'json',
              success: function(response){
 alert('Image inserted successfully');
              },
 error:function(err){

  alert('Something went wrong'); }
            });



}

/*======================Server code======================*/

<?php
if($_POST)
{
   $output="";
   $conn=mysql_connect("localhost","root","");
   $db=mysql_select_db("<db name>");
   mysql_query("SET NAMES 'utf8'");
   mysql_query('SET CHARACTER SET utf8');
   if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
        $output = json_encode(array( //create JSON data
            'type'=>'error',
            'text' => 'Sorry Request must be Ajax POST'
        ));
        die($output);
    }
    $file_attached = false;
if(isset($_FILES['file_attach']))
{
   //Id to update
   $rowId  = $_POST["rowId"];
$file_tmp_name  = $_FILES['file_attach']['tmp_name'];
   $file_content = file_get_contents($file_tmp_name);
//Here iam saving the image in BLOB datatype in MySql database. so iam converting the image into //base64.
   $encode=base64_encode($file_content);
        $sql_edit="<your query here>";
   $sql=mysql_query( $sql_edit);
echo json_encode("File uploaded successfully");
}else{
echo json_encode("No file to upload");
}
echo json_encode($output);

}
?>

//End of Server code
References: http://www.sanwebe.com/2014/04/ajax-contact-form-attachment-jquery-php

Monday 29 September 2014

How to Create an Animated GIF

   
If you've spent any time on the internet at all, you've probably come in contact with ananimated GIF. It's an image file that allows you to feature animated images -- which makes it seem like the image is moving. Look over to the right of this post to see an example of what a GIF looks like.
Pretty cool huh? The best part about GIFs is that they aren't too hard to make -- if you have access to Photoshop (free trial here) and a few minutes to spare, you will have an animated GIF in no time by following the steps below. I'm going to walk you through how to create a GIF using the GIF I created to help promote Marketing Trivia. Note: I am using the CS6 version of Photoshop, but the steps should be similar in other versions. 1) If you already have images created, gather the images you want in a separate folder. To upload them into Photoshop, click 'File,' then 'Scripts,' then 'Load Files Into Stack.' Then select 'Browse' and choose which files you'd like to use in your GIF, then click 'OK.'

1) If you already have images created, gather the images you want in a separate folder. To upload them into Photoshop, click 'File,' then 'Scripts,' then 'Load Files Into Stack.' Then select 'Browse' and choose which files you'd like to use in your GIF, then click 'OK.'


Saturday 27 September 2014

How to Disable Task Manager while running your WinForm Application in C#

CODE

1.start visual studio  as Administrator and create a winform Application


2. Create Two Events  i. Form_Load Event(for disable Task Manager)
                                    ii. Form_Closed  Event(for Enable task Manager)
both of those events contain a method "ShowTaskManager(boolean)" with boolean as argument
like below picture

3. Now define the Method

Add reference file i.e  "Microsoft.Win32 " dll file because we have to use RegistryKey Class
to  access  regedit tool and It's used to view and change settings in the system registry, which contains information(like a TaskManager) about how your computer runs.

4. Now you can run  application (should open this application as Administrator) and open Task Manager it will show a window  like below.
5. When you Close the application and open Task Manager then it works.




LOGIC BEHIND THIS

1.click start button
    (start)                                                                                                      (regedit tool) 

2.Type regedit then click the tool showing like above image in yellow color
3.It will open a window like below and follow 
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\]

4.     in this below code(define in ShowTaskManager() ) means it will create a System key(in below picture ) in policies folder 


 

5.

 When form_Load event will call "ShowTaskManager(true)" this method will invoke and call       "If  part" of this "ShowTaskManager(true)" method .

and that will create a field insight System key i.e  "DisableTaskMgr" with value "1"  means it will not appear Task Manager. 
i.e 

6.

When form_Closed event will call "ShowTaskManager(false)" this method will invoke and call       "Else  part" of this "ShowTaskManager(false)" method .

and that will  Delete System key So as previous  Task Manager.  will appear.




thank you for view my post if any query then comment  fastly .