Skip to content

Instantly share code, notes, and snippets.

Avatar

Din Esh thedineshj

View GitHub Profile
@thedineshj
thedineshj / generateThumbnail.php
Last active Dec 8, 2018
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/)
View generateThumbnail.php
<?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 Dec 6, 2018
PHP-How to create a directory based on current year and current month ?
View createdir.php
<?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 Nov 28, 2018
PHP - How to count number of uploaded files ?
View countfiles.php
<?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 Nov 28, 2018
PHP - How to count number of uploaded files ?
View index.html
<!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 Nov 27, 2018
[PHP] - How to call a function which has the same name as the variable's value inside a class ?
View variable-function-example.php
<?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 Nov 27, 2018
calling a php function with paramters using call_user_func.php
View using-cal-user-func.php
<?php
function sayHello($name){
echo "Hello {$name}";
}
call_user_func("sayHello","John"); // Hello John
?>
@thedineshj
thedineshj / variable-functions.php
Last active Nov 27, 2018
Calling a PHP function, which has the same name as whatever the variable evaluates to
View variable-functions.php
<?php
function doubleIt($num){
echo 2*$num;
}
$functionName="doubleIt";
$functionName(7); // 14
?>
@thedineshj
thedineshj / returningfalse.js
Created Nov 2, 2018
Javascript prevent default form submit
View returningfalse.js
<!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 Nov 2, 2018
Javascript prevent default form submit
View withpreventdefault.js
<!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 Oct 28, 2018
using json web tokens with php
View jswtphp.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=[
You can’t perform that action at this time.