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

  • Home
  • SEARCH
  • 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 829789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:56:20+00:00 2026-05-15T03:56:20+00:00

I have this source code where I got it from net tutsplus. I have

  • 0

I have this source code where I got it from net tutsplus. I have configured it and made it work in one PHP file. It does work by transferring the original image, but it does not generate to the thumbnails folder.

<?php

$final_width_of_image = 100;
$path_to_image_directory = "../../img/events/" . urldecode($_GET['name']) . "/";
$path_to_thumbs_directory = "../../img/events/" . urldecode($_GET['name']) . "/thumbnails/";

function createThumbnail($filename)
{
    if(preg_match('/[.](jpg)$/', $filename)) 
    {
        $im = imagecreatefromjpeg($path_to_image_directory . $filename);
    } 
    elseif(preg_match('/[.](gif)$/', $filename)) 
    {
        $im = imagecreatefromgif($path_to_image_directory . $filename);
    } 
    elseif(preg_match('/[.](png)$/', $filename)) 
    {
        $im = imagecreatefrompng($path_to_image_directory . $filename);
    }

    $ox = imagesx($im);
    $oy = imagesy($im);

    $nx = $final_width_of_image;
    $ny = floor($oy * ($final_width_of_image / $ox));

    $nm = imagecreatetruecolor($nx, $ny);

    imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);

    imagejpeg($nm, $path_to_thumbs_directory . $filename);
    $tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
    echo $tn;
}

if(isset($_FILES['fupload'])) {

    if(preg_match('/[.](jpg)|(gif)|(png)$/', $_FILES['fupload']['name'])) {

        $filename = $_FILES['fupload']['name'];
        $source = $_FILES['fupload']['tmp_name'];
        $target = $path_to_image_directory . $filename;

        move_uploaded_file($source, $target);

        createThumbnail($filename);
    }
}

?>

Basically it is supposed to generate a thumbnail of the uploaded image and store the original image into a different folder.

The paths are correct, it works by getting the folder name in the URL, it does work, but nothing works for the thumbnails folder.

BEFORE you ask this related question, yes, thumbnails generation does work on my server by the PHP GD, I have tested it separately. So this is not the problem. 🙂

How do I get this to work? 🙁

  • 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-05-15T03:56:20+00:00Added an answer on May 15, 2026 at 3:56 am

    Well, first off, use imagecopyresampled(), as it will generate a better thumbnail.

    Secondly, you shouldn’t use the same variable for filesystem directory and for url directory. You should have $filesystem_path_to_thumbs and $url_path_to_thumbs. So you can set them differently.

    Third, you may want to do a size check for both width and height. What happens if someone uploads a tall image? Your thumbnail will be outside the target box (but this may not be a big issue).

    Fourth, you should prob do a check to see if the thumbnail file exists in the thumbs directory before generating the thumbnail (for performance reasons)…

    Finally, the reason it’s actually failing, is $final_width_of_image, $path_to_image_directory and $path_to_thumbs_directory are not defined within the function. Either:

    1. Make them global at the start of the function, so you can access them inside of the function global $final_width_of_image, $path_to_image_directory, $path_to_thumbs_directory;

    2. Make them arguments to the function: function createTumbnail($image, $width, $path_to_images, $path_to_thumbs) {

    3. Hard code them inside of the function (Move their declaration from outside the function to inside the function).

    Personally, I’d do #2, but it’s up to what your requirements and needs are…

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

Sidebar

Ask A Question

Stats

  • Questions 495k
  • Answers 495k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The IIS running in Integrated mode, so i finally found… May 16, 2026 at 11:17 am
  • Editorial Team
    Editorial Team added an answer When installing them, specify custom (not default) location for them. May 16, 2026 at 11:17 am
  • Editorial Team
    Editorial Team added an answer When you load an image with Loader it is stored… May 16, 2026 at 11:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Background: We have a TFS server setup where me manage our source code and
I have got a problem on casting an object to one of it's base
Hi all i am the next issue this is my source code of my
I've had this intermittent issue when using asp.net. My site is dynamically compiled. Sometimes
I have a .NET project that's always been built/run by/on 32 bit machines. I
I have an existing VS 2005 Std .NET Compact Framework application that I want
I've got a small but growing framework for building .net systems with ruby /
I have stumbled upon the following F77 yacc grammar: http://yaxx.cvs.sourceforge.net/viewvc/yaxx/yaxx/fortran/fortran.y?revision=1.3&view=markup . How can I
I have an old ASP.NET application. We send out httpWebRequest to a remote REST
I have developed an ASP.NET MVC 2 website, and now need to deploy it

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.