PHP

PHP – detecting new uploaded images and sending an e-mail with attachments

This specific content was written 4 years ago. Please keep this in mind as it may be outdated and not adhering to best-practices.

Quick example today if a php script that I wanted to detect new uploaded images, and then send an e-mail.
I think it’s pretty self-explanatory so won’t go into details. However, keep in mind that it’s mostly simple PHP (not too object-oriented) and also that I make use of the wp_mail function.

$menPath = "path-to-uploaded-files/*.jpg";    
 $menLast  = file_get_contents('timestampFile.txt');    
 if($menLast === false){
     echo 'it is zero';
     $menLast = 0;
 }
 $menFiles = glob($menPath);
 
 $menFiles = array_filter($menFiles, function ($file) use ($menLast) { 
   
    $mentest = $menLast - filemtime($file);
    return filemtime($file) > $menLast; });
 file_put_contents('timestampFile.txt', time());

 if (count($menFiles) > 0 )
 {
 $menText =     "images uploaded\r\nFound images count:".count($menFiles)       
        ."Current last timestamp recorded:".date('d-m-Y h:i:s', $menLast )."\r\n"
        ."Images found:\r\n";
 <code>foreach ($menFiles as &$file) {     $menText = $menText.date('d-m-Y h:i:s', filemtime($file))."-".basename($file)."\r\n"; }</code>
     wp_mail( "yourEmail@gmail.com", "files-uploaded", $menText ,'',$menFiles);
 }
 ?>

Laravel 5 and simple Forms workaround

This specific content was written 10 years ago.
Please keep this in mind as it may be outdated and not adhering to best-practices.

Here is a simple example of using laravel 5 powerful forms to deliver a secure and fast result!
To make our lives easier we need to install the HTML package!

In file /compojer.json we add:
"require": {
"laravel/framework": "5.0.*",
"laravelcollective/html": "~5.0"
},

Next add the service provider and aliases.
In /config/app.php we update the following:

'providers' => [
'Illuminate\Html\HtmlServiceProvider',
],

'aliases' => [
'Form'=> 'Illuminate\Html\FormFacade',
'HTML'=> 'Illuminate\Html\HtmlFacade',
],

More

Laravel 5 TIPS For Beginners!

This specific content was written 10 years ago.
Please keep this in mind as it may be outdated and not adhering to best-practices.

Here are some tips you might find handy when you think you have done everything according to the tutorials!

In formrequests to authorise access only for registered/signed users we add

use Auth;
public function authorize()
{
if ( !Auth::check() )
return false;
return true;
}

More

JQuery Calendar and PHP: Handling Inserts

This specific content was written 11 years ago.
Please keep this in mind as it may be outdated and not adhering to best-practices.

1) Getting Current Time in Javascript

The ISO 8601 date format can be utilized to convert the date on the browser side to a format that include timestamp information. Quoting from here:

Note that the “T” appears literally in the string, to indicate the beginning of the time element. Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator (“Z”). Used in ATOM RSS feeds.

function fnISO() {
// Only works in Firefox using ECMAScript 5
var now = new Date().toISOString();
alert(now);
}

Result: 2009-08-06T23:36:31.390Z

More

Encrypt in VB.NET and Decrypt in PHP 4 Using Phpseclib0.3.0

This specific content was written 13 years ago.
Please keep this in mind as it may be outdated and not adhering to best-practices.

Originally I had found code from: Encrypt in VB.NET and Decrypt in PHP and Vice Versa .

Everything worked well, until I realized that the specific webserver I was writing code for ran PHP 4…No mcrypt_decrypt.

Hence I discovered PHPSecLib has the Rijndael algorithm implemented as PHP code.
Following please find code to check if mcrypt exists and react differently (where $line is the encrypted text):


if(function_exists('mcrypt_decrypt'))
$dec = decryptRJ256($ky, $iv, $line);
else
$dec = decryptRJ256_PHPSECLIB($ky, $iv, $line);

More

if(!cn_cookies_accepted()){ location.href="http://www.google.com"; } alert('test');