Friday, June 28, 2013

How to handel warning error using exceotion in php

<?php
function custom_error($errno, $errstr, $errfile, $errline){
echo "Xml url not valid $errfile";
die();
}
function getData() {
 if(!set_error_handler('custom_error')){
    echo "Error :";

    }

    try {
        $xml = new SimpleXMLElement('http://publisher.usb.api.shopping.com/publisher/3.0/reasdfst/GeneralSearch?apiKey=752d3653-2797-4544-9ca1-asdf&trackingId=sadf&numItems=1&&keyword=strollers', null, true);
    }catch(Exception $e) {
        restore_error_handler();

    }

    return $xml;
}

    $xml = getData();


?>

Tuesday, June 25, 2013

download and save image into server base64 decode using php

 define('UPLOAD_DIR', 'C:\inetpub\wwwroot\PHP\images\Shareimage/');
 $imagePath=$_POST['img_val'];


       /* header("Content-Transfer-Encoding: binary");
        header("Content-Type: image/jpg");
        header("Content-Disposition: attachment; filename=custom-img.jpg");
        //start feeding with the file
readfile($imagePath);
*/



 
$imagePath = str_replace('data:image/jpeg;base64,', '', $imagePath);
$imagePath = str_replace(' ', '+', $imagePath);
$data = base64_decode($imagePath);
$file = UPLOAD_DIR  .'customshare.jpeg';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';

Monday, June 10, 2013

mysql range between query example get price between range value

i think any one can help by this query range between query example 

SELECT *
FROM `wp_lalyl_wp_discount_price`
WHERE `p_id` =14
AND 3
BETWEEN `min_qty`
AND `max_qty`

Sunday, June 9, 2013

how to redirect query string value to paypal standard payment method

 $query = array();
    $query['notify_url'] = 'http://yourwesite.com/ipn';
    $query['cmd'] = '_cart';
    $query['upload'] = '1';
    $query['business'] = 'nayak.bikash@yahoo.com';
    $query['address_override'] = '1';
    $query['first_name'] = $first_name;
    $query['last_name'] = $last_name;
    $query['email'] = $email;
    $query['address1'] = $ship_to_address;
    $query['city'] = $ship_to_city;
    $query['state'] = $ship_to_state;
    $query['zip'] = $ship_to_zip;
    $query['item_name_'.$i] = $item['description'];
    $query['quantity_'.$i] = $item['quantity'];
    $query['amount_'.$i] = $item['info']['price'];

    // Prepare query string
    $query_string = http_build_query($query);

    header('Location: https://www.paypal.com/cgi-bin/webscr?' . $query_string);

Thursday, June 6, 2013

html2canvas- Take Screenshot of Web Page and Save It to Server (Javascript and PHP


FeedBack is important. Usually, end-users struggle to clarify their problems. And you might be unreachable for a phone call or remote connection.
That causes a huge need of visualization. First solution that appears in mind is to capture the current screen of user.
However, when I tried to implement that, it wasn’t so easy as I expected. Some old ways offer ActiveX but it seems too outdated. Since there’s a bridge needed between client side and server, JS libraries are the best way.
There’s a great library, html2canvas. It is told to be reverse-engineered version of Google Plus’ way of taking screenshots.
When I first discovered this library, it took me a while to use for simplest implementation. I just wanted to visualize a div element. However, there was no single page to tell the whole path to follow, thus I had to combine various sources.
Here’s how you can easily use for taking a screenshot of a div:
1- Import libraries
There are 3 libraries to import:
  • jquery.js
  • html2canvas.js
  • jquery.plugin.html2canvas.js
You can download html2canvas and html2canvas jQuery plugin from this link.
Note: The source link contains html2canvas v0.40. I recommend you to check for a newer version and use it instead from official html2canvas site.
I have used jquery.min.js v1.7.1 but you can try other versions. For this jQuery library, use this link.
Here’s first lines of code:
1
2
3
4
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="js/html2canvas.js"></script>
<script type="text/javascript" src="js/jquery.plugin.html2canvas.js"></script>
<!-- -->
2- Create your div
In my code, I used html2canvas for a div. You can use the whole body tag instead, it’s up to you.
Attach a div element to the page with a certain id:
1
2
3
<div id="target">
<!-- Render your page inside of this div. -->
</div>
3- Create a button and a hidden form
This part is important. In order to save the image to server, we need to pass captured image data with a form field.
In 4th step, you’ll see JavaScript code that writes the image data to hidden field and posts the form.
1
2
3
4
<input type="submit" value="Take Screenshot Of Div" onclick="capture();" />
<form method="POST" enctype="multipart/form-data" action="save.php" id="myForm">
    <input type="hidden" name="img_val" id="img_val" value="" />
</form>
4- JavaScript Code
1
2
3
4
5
6
7
8
9
10
function capture() {
    $('#target').html2canvas({
        onrendered: function (canvas) {
            //Set hidden field's value to image data (base-64 string)
            $('#img_val').val(canvas.toDataURL("image/png"));
            //Submit the form manually
            document.getElementById("myForm").submit();
        }
    });
}
5- Use the posted values
Here I used a form to post the value. You can use Ajax calls or whatever. I have a PHP file, save.php. In this file, we will both show the picture and save it to the server.

<?php
$LgPath=$_POST['img_val'];

        header("Content-Transfer-Encoding: binary");
        header("Content-Type: image/png");
        header("Content-Disposition: attachment; filename=custom-img.png");
        //start feeding with the file
readfile($LgPath);