PHP Web Development Wordpress

WordPress page template to access htaccess protected pdf file

WordPress page template to access htaccess protected pdf file: <?php /* pdf file download provision */ $download_success = false; $file_found = false; if(current_user_can( ‘manage_options’ )){ $doc = esc_url($_GET[‘doc’]); echo $file = str_replace(‘https://wma.ie/’,ABSPATH ,$doc); if (file_exists($file)) { $file_found = true; ob_clean(); flush(); header(‘Content-Description: File Transfer’); header(‘Content-Type: application/octet-stream’); header(‘Content-Disposition: attachment; filename=’.basename($file)); header(‘Content-Transfer-Encoding: binary’); header(‘Expires: 0’); header(‘Cache-Control: must-revalidate’); […]

PHP Web Development

Base64 encoded image save by PHP

How to save base64 encoded image in a file using PHP <?php  /// define upload directory     define(‘UPLOAD_DIR’, ‘images/’); /// explode  on ;base64  to know image type from encoded string    $image_parts = explode(“;base64,”, $_POST[‘image’]);     $image_type_aux = explode(“image/”, $image_parts[0]);     $image_type = $image_type_aux[1];     $image_base64 = base64_decode($image_parts[1]);    /// create file path with file name     $filepath = UPLOAD_DIR .’img_’. […]