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 315041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:15:18+00:00 2026-05-12T08:15:18+00:00

I have the php code below which help me get a photo’s thumbnail image

  • 0

I have the php code below which help me get a photo’s thumbnail image path in a script

It will take a supplied value like this from a mysql DB ‘2/34/12/thepicture.jpg’
It will then turn it into this ‘2/34/12/thepicture_thumb1.jpg’

I am sure there is a better performance way of doing this and I am open to any help please

Also on a page with 50 user’s this would run 50 times to get 50 different photos

// the photo has it is pulled from the DB, it has the folders and filename as 1
$photo_url = '2/34/12/thepicture_thumb1.jpg';
//build the full photo filepath
$file = $site_path. 'images/userphoto/' . $photo_url;
// make sure file name is not empty and the file exist 
if ($photo_url != '' && file_exists($file)) {
    //get file info
    $fil_ext1 = pathinfo($file);
    $fil_ext = $fil_ext1['extension'];
    $fil_explode = '.' . $fil_ext;
    $arr = explode($fil_explode, $photo_url);
    // add "_thumb" or else "_thumb1" inbetween 
    // the file name and the file extension 2/45/12/photo.jpg becomes 2/45/12/photo_thumb1.jpg
    $pic1 = $arr[0] . "_thumb" . $fil_explode;
    //make sure the thumbnail image exist
    if (file_exists("images/userphoto/" . $pic1)) {
        //retunr the thumbnail image url
        $img_name = $pic1;
    }
}

1 thing I am curious about is how it uses pathinfo() to get the files extension, since the extension will always be 3 digits, would other methods of getting this value better performance?

  • 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-12T08:15:18+00:00Added an answer on May 12, 2026 at 8:15 am

    Performance-wise, if you’re calling built-in PHP functions the performance is excellent because you’re running compiled code behind the scenes.

    Of course, calling all these functions when you don’t need to isn’t a good idea. In your case, the pathinfo function returns the various paths you need. You call the explode function on the original name when you can build the file name like this (note, the ‘filename’ is only available since PHP 5.2):

    $fInfo = pathinfo($file);
    $thumb_name = $fInfo['dirname'] . '/' . $fInfo['filename'] . '_thumb' . $fInfo['extension'];
    

    If you don’t have PHP 5.2, then the simplest way is to ignore that function and use strrpos and substr:

    // gets the position of the last dot
    $lastDot = strrpos($file, '.');
    // first bit gets everything before the dot,
    // second gets everything from the dot onwards
    $thumbName = substr($file, 0, $lastDot) . '_thumb1' . substr($file, $lastDot);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 171k
  • Answers 171k
  • 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 An enumeration is (almost but not really) an integer, but… May 12, 2026 at 2:19 pm
  • Editorial Team
    Editorial Team added an answer O(min(n,m)) time is impossible: Take two lists [x;x;...;x;y] and [x;x;...;x;z].… May 12, 2026 at 2:19 pm
  • Editorial Team
    Editorial Team added an answer You can control the keyboard and the mouse with python… May 12, 2026 at 2:19 pm

Related Questions

I have the php code below which help me get a photo's thumbnail image
I'm currently working on posting a file from a C# application to an image
I would like to submit information to a mySql database using php and ajax.
I have a MySQL database with multiple tables, each of which have the same
I have a form which has a input textbox and submit button. On submission

Trending Tags

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

Top Members

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.