Commit b0f128a890e0fa00d14f83d1092a1cba32914c7c

Authored by Theoziran Lima
1 parent f693308a
Exists in master and in 1 other branch issue488

Ajustes para baixar as imagens remotas em tempo de execução

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-remote.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);
... ...