Skip to content

Instantly share code, notes, and snippets.

View Coysh's full-sized avatar
👋

Tim Coysh Coysh

👋
View GitHub Profile
@nciske
nciske / add_screenshot_as_ogimage.php
Last active January 19, 2021 02:36
Add screenshot of current page as Open Graph image. Primes the wp.com cache by including the image at the bottom of the page as well.
<?php
add_action( 'wp_head', 'add_screenshot_as_ogimage' );
function add_screenshot_as_ogimage(){
// default width = 1500 -- 200px minimum, Facebook recommends 1500x1500, max image size of 5mb
echo '<meta property="og:image" content="http://s.wordpress.com/mshots/v1/'.urlencode( $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ).'?w=1500"/>';
@ebidel
ebidel / handle_file_upload.php
Created April 18, 2012 03:23
Uploading files using xhr.send(FormData) to PHP server
<?php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,