Skip to content

Instantly share code, notes, and snippets.

View thedineshj's full-sized avatar

Din Esh thedineshj

View GitHub Profile
@thedineshj
thedineshj / generateThumbnail.php
Last active December 8, 2018 20:07
This function will generate a thumnail in png format for a pdf document using - ImageMagick ( http://php.net/imagick ) , Ghostscript (https://sourceforge.net/projects/ghostscript/)
<?php
/***
* This function will generate a thumbnail in png format for a pdf document using
* ImageMagick - http://php.net/imagick
* Ghostscript - https://sourceforge.net/projects/ghostscript/
* @param $source - string - relative path to the source pdf (for example : ./originals/lorem-ipsum.pdf )
* @param $destination - string - relative path to the directory where you want to place the generated thumbnail (for example : './thumnails')
* @param $fileName - string - file name of the thumbnail with out extension (for example : pdfthumbdemo )
* @param width - number - width of the thumbnail
* @param height - number - height of the thumbnail
@thedineshj
thedineshj / createdir.php
Created December 6, 2018 20:15
PHP-How to create a directory based on current year and current month ?
<?php
// - current year (for example : 2018)
$year=date('Y');
// - current month (for example : 12)
$month=date('m');
// directory path
$directory="./{$year}/{$month}/";
@thedineshj
thedineshj / countfiles.php
Last active November 28, 2018 21:06
PHP - How to count number of uploaded files ?
<?php
if(isset($_POST['submit'])){
function countUploadedFiles($name){
/*
if a user submits the form
with out selecting any files
*/
if($_FILES[$name]['size'][0]==0){
@thedineshj
thedineshj / index.html
Last active November 28, 2018 20:56
PHP - How to count number of uploaded files ?
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Count File Uploads</title>
</head>
<body>
<form method="post" action="./countfiles.php" enctype="multipart/form-data">
@thedineshj
thedineshj / variable-function-example.php
Last active November 27, 2018 11:32
[PHP] - How to call a function which has the same name as the variable's value inside a class ?
<?php
class Human{
public function laugh() {
echo "<br />";
echo "Lmao";
}
public function cry(){
echo "<br />";
echo "I'm crying";
}
@thedineshj
thedineshj / using-cal-user-func.php
Created November 27, 2018 11:12
calling a php function with paramters using call_user_func.php
<?php
function sayHello($name){
echo "Hello {$name}";
}
call_user_func("sayHello","John"); // Hello John
?>
@thedineshj
thedineshj / variable-functions.php
Last active November 27, 2018 11:03
Calling a PHP function, which has the same name as whatever the variable evaluates to
<?php
function doubleIt($num){
echo 2*$num;
}
$functionName="doubleIt";
$functionName(7); // 14
?>
@thedineshj
thedineshj / returningfalse.js
Created November 2, 2018 14:57
Javascript prevent default form submit
<!DOCTYPE html>
<html>
<head>
<title> Javascript prevent default form submit </title>
</head>
<body>
<form id="form" action="home.php" method="post">
<label for="username">User name</label>
<input name="username" type="text" id="username" />
<button type="submit">Submit</button>
@thedineshj
thedineshj / withpreventdefault.js
Created November 2, 2018 14:50
Javascript prevent default form submit
<!DOCTYPE html>
<html>
<head>
<title> Javascript prevent default form submit </title>
</head>
<body>
<form id="form" action="home.php" method="post">
<label for="username">User name</label>
<input name="username" type="text" id="username" />
<button type="submit">Submit</button>
@thedineshj
thedineshj / jswtphp.php
Last active October 28, 2018 13:26
using json web tokens with php
<?php
require './php-jwt/BeforeValidException.php';
require './php-jwt/ExpiredException.php';
require './php-jwt/JWT.php';
require './php-jwt/SignatureInvalidException.php';
use \Firebase\JWT\JWT;
$data=[