Skip to content

Instantly share code, notes, and snippets.

@caefer
Created April 5, 2011 12:02
Show Gist options
  • Select an option

  • Save caefer/903474 to your computer and use it in GitHub Desktop.

Select an option

Save caefer/903474 to your computer and use it in GitHub Desktop.
<?php
namespace MyProject\MyBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class ImageController extends Controller
{
public function proxyAction($url)
{
$url = urldecode($url);
switch (strtolower(pathinfo($url, PATHINFO_EXTENSION))) {
case 'gif':
$contentType = 'image/gif';
break;
case 'jpg':
$contentType = 'image/jpeg';
break;
case 'png':
$contentType = 'image/png';
break;
}
$response = new Response(file_get_contents($url));
$response->headers->set('Content-Type', $contentType);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment