title: php call php file as image outside public directory
body: <p>In directory privateimgdir outside public directory I have file create_img.php that creates a png image on the fly. I need to serve that img from outside the public dir to avoid other sites to directly access the output image.</p>
  
  <p>To do so, I'm trying to use a php proxy script. Inside public_scripts directory I have the file take_img.php with code as follows:</p>
  
  <pre><code>&lt;?php
  
  $file_to_get = basename(urldecode($_GET['file']));
  
  $private_image_dir = "../../privateimgdir/";
  
  $contents = file_get_contents($private_image_dir . $file_to_get);
  
  header('Content-type: image/png');
  
  echo $contents;
  
  ?&gt;
  </code></pre>
  
  <p>Now I try to call take_img.php script and to pass create_img.php filename as a parameter by using this code:</p>
  
  <pre><code>echo "&lt;a href='public_scripts/take_img.php?file=create_img.php'&gt;&lt;/a&gt;";
  </code></pre>
  
  <p>But I get no output. Where am I wrong?</p>