Skip to content

Instantly share code, notes, and snippets.

@tranchausky
Created October 4, 2022 01:52
Show Gist options
  • Select an option

  • Save tranchausky/b814de0e19abbf4513877d6ab6af1b14 to your computer and use it in GitHub Desktop.

Select an option

Save tranchausky/b814de0e19abbf4513877d6ab6af1b14 to your computer and use it in GitHub Desktop.
view 404 image from link with certificate
RewriteEngine On
ErrorDocument 404 /images/mywebsite/404.php
<?php
//http://localhost:90/blog/wp-content/uploads/2019/03/Vincent-VIRIOT-1024x570.jpg
//var_dump($_SERVER);die;
$request_url = $_SERVER['REQUEST_URI'];
//var_dump($request_url);die;
$character = '/images/mywebsite/';
if (strpos($request_url, $character) !== false) {
//echo 'true';
$bodytag = str_replace($character, "", $request_url);
//var_dump($bodytag);
//http://localhost:90/images/menuActiveArrow.png
$file = 'https://qa.website.local/images/mywebsite/' . $bodytag;
//var_dump($file);die;
//$current = file_get_contents($file);
//var_dump($current);
//$base_name = basename($bodytag);
//var_dump($base_name);die;
//$save_url = 'images/'.$base_name;
//$save_url = ''.$base_name;
//file_put_contents($save_url, $current);
return_image_content($file, $bodytag);
}
//echo 'end';
//die;
function return_image_content($file_out, $bodytag = '')
{
//$file_out = "myDirectory/myImage.gif"; // The image to return
//var_dump($file_out);die;
$ch = curl_init();
//$certificate = 'E:/Downloads/usbwebserver/cacert.pem';
$certificate = dirname(__FILE__).'/cacert.pem';
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $certificate_location);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $certificate_location);
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $file_out);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// grab URL and pass it to the browser
$urlContent = curl_exec($ch);
if (!curl_errno($ch)) {
$info = curl_getinfo($ch);
header('Content-Type: ' . $info['content_type']);
echo $urlContent;
}
curl_close($ch);
$isInFolder = preg_match("/^(.*)\/([^\/]+)$/", $bodytag, $filepathMatches);
if ($isInFolder) {
$folderName = dirname(__FILE__) . '/' . $filepathMatches[1];
//var_dump($folderName);die;
$fileName = $filepathMatches[2];
if (!is_dir($folderName)) {
mkdir($folderName, 0777, true);
}
//var_dump($folderName);die;
}
//file_put_contents(dirname(__FILE__) . '/' . $bodytag, $urlContent);
/*
$remoteImage = $file_out;
$imginfo = getimagesize($remoteImage);
var_dump($imginfo);die;
header("Content-type: {$imginfo['mime']}");
readfile($remoteImage);
*/
die;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment