Skip to main content

Posts

Showing posts from September, 2017

Currency converter with php using Yahoo Api

Hi, Here is a simple PHP code, using which you can get the live currency. API Provider - ( http://finance.yahoo.com/ ) In this example i am getting the value of USD to INR. <?php $from   = 'USD'; $to     = 'INR'; $url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from . $to .'=X'; $filehandler = @fopen($url, 'r'); if ($filehandler) { $data = fgets($filehandler, 4096);   fclose($filehandler); } $InfoData = explode(',',$data); $convertedValue= $InfoData[1]; echo $convertedValue; ?>

Function to convert base64_string to image and upload it to directory

//Code to call function $base64file = $request->input('filename'); $input['filename'] = rand().'.png'; $canvasimagepath = public_path('files/'.$input['filename']); //uploaded path with image name base64_to_jpeg($base64file, $canvasimagepath);  ///Calling function to upload image from base64_string //Function to convert base64_string to image and upload function base64_to_jpeg($base64_string, $output_file) { $ifp = fopen($output_file, "wb"); $data = explode(',', $base64_string); fwrite($ifp, base64_decode($data[1])); fclose($ifp); return $output_file; }

Delete Directory and it's files using php

To delete directory and its Files using php. please use below code: if (!is_dir('directorypath'))    {      mkdir( 'directorypath ');    }    $dir = 'directorypath ';      foreach (glob($dir."/*.*") as $filename) {        if (is_file($filename)) {            unlink($filename);        }    }    rmdir($dir);

Simple Steps to do more Secure your Ajax Call

Following the Simple Steps to do more Secure your Ajax Call. 1. Ajax Check - Ajax url must give Response when request is from ajax. if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&  strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { echo "Ajax Call"; } else{ echo "No Ajax Call"; } 2. Domain Check - Ajax url must give response, when request from your own server. if(!empty($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']=="WWW.mydomain.com/url") { //Request from my server }

Remove index.php using htaccess in ubuntu

To remove index .php from web url in codeigniter using htaccess Step 1 : Add this in htaccess file <IfModule mod_rewrite . c > RewriteEngine On #RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] </IfModule> Step 2 : Remove index.php in codeigniter config $config[ 'base_url' ] = '' ; $config[ 'index_page' ] = '' ; Step 3 : Allow overriding htaccess in Apache Configuration (Command) sudo nano /etc/apache2/apache2.conf and edit the file & change to AllowOverride All for www folder Step 4 : Enabled apache mod rewrite (Command) sudo a2enmod rewrite Step 5 : Restart Apache (Command) sudo /etc/init.d/apache2 restart or sudo service apache2 restart

Remove blank space or &65279 from html or website

If your website showing "&'#'65279;" it adds an blank space to your website.. To remove this download the below file and paste it into your root directory and run that file like. localhost/bom.php It will remove the string and show the file name which has the given utf8 string. Click here to download If your directory has larger number of file please make following update in php.ini file: max_execution_time=-1 memory_limit=-1 and restart your server. now run your site.