Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9159403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:29:02+00:00 2026-06-17T13:29:02+00:00

I am trying to create thumbnail pics using GD lib in Cake PHP. I

  • 0

I am trying to create thumbnail pics using GD lib in Cake PHP.

I can write the resized thumbnail to the tmp directory, and create the sensible URL to show the image from the tmp directory:

//set up empty GD resource  
$tmp = imagecreatetruecolor(200*$iw/$ih, 200);
//create thumbnail image in the empty GD resource
imagecopyresampled($tmp, $src, 0, 0, 0, 0,200*$iw/$ih, 200, $iw, $ih);
//build full path to thumbnail in the cakephp tmp directory
$thumbfile = APP.'tmp/thumb.jpg';
//build URL path to the same thumbnail
$thumblink = $this->webroot.'tmp/thumb.jpg';
//write jpeg to the tmp directory
$return=imagejpeg($tmp,$thumbfile);
//write out the image to client browser
echo "<img=\"$thumblink\" alt=\"thumb\" height=\"200\" width=\"200*$iw/$ih\">";

The thumbnail gets created and written to the tmp directory, but when I try to access the URL I get the following error message:

Error: TmpController could not be found.
Error: Create the class TmpController below in file: app/Controller/TmpController.php

Obviously I have a routing error – Cake tries to call the tmp controller, in stead of looking in the tmp direcectory. How can I fix this, or is there an alternative way to serve temporary thumbnails using GD lib?
I am planning to create unique thumbnails per session or user, but I need to get this working first.

Routing in Config/routes.php:

Router::connect('/', array('controller' => 'MsCake', 'action' => 'index'));
Router::connect('/pages/*', array('controller' => 'pages'));
CakePlugin::routes();

I looked at ThumbnailHelper, but that doesn’t use GD Lib. I also need to be able to access files stored on non-apache accessible directories from outside, but I can’t even access any temporary symbolic links to get to them. eg.

  • create a temporary symbolic link in the tmp directory, pointing to the file in question.
  • create a HTML link, pointing to the symbolic link using $this->webroot.’tmp/link-to-myfile’, as above

…and I get the same error as above – Error: TmpController could not be found.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:29:03+00:00Added an answer on June 17, 2026 at 1:29 pm

    Don’t do that

    If you do anything to make files in the tmp dir web-accessible – you’re severely lowering your site’s security. Things in the tmp directory are never supposed to be web accessible.

    Put your images in the webroot

    A better idea is to put your temporary images in the webroot directory – which is the only directory that is ordinarily web accessible. For example:

    $filename = md5($userId);
    $thumbfile = APP.'webroot/img/cache/' . $filename . '.jpg';
    
    ...
    $url = '/img/cache/' . $filename . '.jpg';
    

    Or route to a controller action

    Alternatively, route to a controller action to handle the request using the media view class. Note however though, that serving images with php is not free – there can be a noticable delay while your request is processed – where’as pointing at a static file does not have this cost/risk since it’s just the webserver taking care of serving the content.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I'm trying to create a thumbnail image on the client side using javascript and
I am trying to create a thumbnail gallery using XML databinding. But the data
I'm trying to create thumbnail from url with WKhtmltoImage by executing this command :
I'm trying to create a thumbnail / cutout of a larger image and it
Ok so I am trying create a login script, here I am using PHP5
I am trying to create and save a thumbnail image when saving the original
I'm trying to create a function which will add an overlay to a thumbnail
What I'm trying to do is create a class that I can quickly attach
I am trying to create a video thumbnail for a file : 1- the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.