Commit e2f88f6c91df0c9d1d01b1c70fa5499cbc16f412

Authored by Theoziran Lima
2 parents da35459a eb8ee498
Exists in master and in 1 other branch issue488

Merge pull request #397 from theoziran/issue326

Fix pensandoodireito/participacao-sitebase#326
Showing 2 changed files with 31 additions and 0 deletions   Show diff stats
config/htaccess-vagrant
... ... @@ -6,6 +6,8 @@ RewriteRule ^index\.php$ - [L]
6 6 # add a trailing slash to /wp-admin
7 7 RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
8 8  
  9 +RewriteRule (^\/wp\-content\/[^.]+\.(jpe?g|gif|bmp|png))$ /file.php?src=$1 [L]
  10 +
9 11 RewriteCond %{REQUEST_FILENAME} -f [OR]
10 12 RewriteCond %{REQUEST_FILENAME} -d
11 13 RewriteRule ^ - [L]
... ...
src/file-remote.php 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +<?php
  2 +$path = $_GET{'src'};
  3 +
  4 +$dirs = explode('/', $path);
  5 +$img = implode('/', $dirs);
  6 +
  7 +if(strpos($img, ".jpg") !== false || strpos($img, ".jpeg")){
  8 + $contentType = "image/jpeg";
  9 +}elseif(strpos($img, ".png") !== false){
  10 + $contentType = "image/png";
  11 +}else{
  12 + $contentType = "image/gif";
  13 +}
  14 +
  15 +header("Content-Type: {$contentType}", true);
  16 +
  17 +if(file_exists($img)){
  18 + $content = file_get_contents($img);
  19 +}else{
  20 + array_pop($dirs);
  21 + $localDir = implode('/', $dirs);
  22 + if(!file_exists($localDir) || is_dir($localDir)){
  23 + mkdir($localDir, 777, true);
  24 + }
  25 + $content = file_get_contents("http://pensando.mj.gov.br/{$img}");
  26 + file_put_contents($img, $content);
  27 +}
  28 +
  29 +die($content);
... ...