Add Authorization to your Website using .htaccess file

You have to create 2 files first is .htaccess file and another is .htpasswd file
code of .htaccess file :


#deny from all
allow from all
AuthUserFile path-of-your-.htpasswd-file e.g. /usr/home/aftab/public_html/store/.htpasswd
AuthType Basic
AuthName "Authorization Required"
Require valid-user

and code of .htpasswd file :


admin:$apr1$q6ubsdpg$4wxS3b2npMlpfT3JbqRkW.
//admin is the username
// and password is encrypted by MD5

.htaccess-view

Advertisements

JQuery Code Snippet to “Translate your website in many languages”

You just need to add the script in your HTML which is given below:


<!-- If you already have jQuery embeded in your page, remove the following line: -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<!-- Start Translate This button  -->
<script src="http://s1.translationcloud.com/_3_0/javascript/e.js?translate_this_src=hi"></script>
<div class="translate_this notranslate" style="margin-top:20px;">
<a class="translate_this_drop translate_this_tc_icon" title="Translate" href="http://translationcloud.com">translation services</a>
<a class="translate_this_drop translate_this_translate_text" title="Translate" href="http://translationcloud.com">Translate</a>
<span class="translate_this_separator"> | </span>
<a class="translate_this_no_drop" title="English" href="http://translationcloud.com/languages/english/" rel="en">English translation</a>
<a class="translate_this_no_drop" title="Spanish" href="http://translationcloud.com/languages/spanish/" rel="es">Spanish</a>
<a class="translate_this_no_drop" title="German" href="http://translationcloud.com/languages/german/" rel="de">German</a>
<a class="translate_this_no_drop" title="Chinese" href="http://translationcloud.com/languages/chinese/" rel="zh-CHS">translate Chinese</a>
</div> <!-- End Translate This button -->

Create PDF file of any URL

Now it is very easy to create a PDF file of any page or any reports etc.
Simply, you need to create the html page for which you need to create PDF.

For eg: If I want to create PDF of Google.com than I will simply put url of Google.com as shown in below example:


$url = "http://www.google.com";
$file = phptopdf_url($url, 'pdf_examples/', "GOOGLE_HOMEPAGE.pdf");
// First Param : specifies the URL whose PDF to generate
// Second Param : specifies the storage location
// Third Param : defines the PDF filename 

I had created a function called "phptopdf_url()" to make it more clear
and structured. The function is follows: function phptopdf_url($source_url,$save_directory,$save_filename) { $API_KEY = 'd6s73mtjk85di7hm3'; $url = 'http://phptopdf.com/urltopdf.php?key='.$API_KEY.'&url='.urlencode($source_url); $resultsXml = file_get_contents(($url)); file_put_contents($save_directory.$save_filename,$resultsXml); return $save_directory.$save_filename; }

By executing above given code you can generate PDF. That’s it. ­čÖé

Create Tiny URL from PHP

To create tiny url from PHP code we can use following:


//gets the data from a URL
function get_tiny_url($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

//test it out!
$new_url = get_tiny_url('https://aftabmuni.wordpress.com/2014/08/0
5/create-tiny-url-from-php/');

//returns http://tinyurl.com/q5nltyy

echo $new_url

Thats It…!! Enjoy

Creating Thumbnail Images From Video

To Create thumbnail image for the video which is uploaded then you can use a library┬ácalled “ffmpeg”
This library is used to manipulate videos.


Steps for creating thumbnail from video:

1). Download the ffmpeg library into the system, or you can add ffmpeg-php extension.

2). To see that ffmpeg is installed you can check it by viewing phpinfo() function.

3).
$tmpfile = $_FILES['video']["tmp_name"];
$file = $_FILES['video']["name"];
$abc = date("dmyHis");
$insertVideo = $abc . $file;
move_uploaded_file($tmpfile, $sub_dir . $insertVideo);
$image_name = $abc . "_image.jpg";
$file_thumb = create_movie_thumb($sub_dir . $insertVideo,$sub_dir,$image_name);

Below is the actual function to create thumbnail

function create_movie_thumb($src_file,$fullpath,$image_name)
{
global $CONFIG, $ERROR;
if ($_SERVER['HTTP_HOST'] == 'dev.yourapp.com') {
$CONFIG['ffmpeg_path'] = 'c:/ffmpeg/bin/'; // path of your ffmpeg bin folder this is for windows
}else{
$CONFIG['ffmpeg_path'] = '/usr/local/bin/'; // this path is for linux
}
$CONFIG['fullpath'] = $fullpath;
$CONFIG['debug_mode'] = 1;

$src_file = $src_file;
$imgname = $image_name;
$dest_file = $CONFIG['fullpath'].$imgname;

$cmd = "\"".str_replace("\\","/", $CONFIG['ffmpeg_path'])."ffmpeg\" -i ".str_replace("\\","/" ,$src_file )." -an -ss 00:00:03 -r 1 -vframes 1 -y ".str_replace("\\","/" ,$dest_file);
exec($cmd);
echo $cmd;
}