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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:36:05+00:00 2026-06-17T11:36:05+00:00

I store the original image path(included file name) in db when upload an image.

  • 0

I store the original image path(included file name) in db when upload an image.

For example:
img/uploaded/photo.jpg

Then I generate its thumbnail and store in below directory NOT in db.

/img/uploaded/thumbs/photo_thumb.jpg

And I have following function but no idea how to get the thumb which belong to the url in db.

//ie: $file is img/uploaded/photo.jpg
public function get_thumb($file)
{
    //get the path without filename
    $get_path = dirname($file) . "/thumbs/";

    //result img/uploaded/thumbs/  (how can i get the photo_thumb.jpg) here?
    return $get_path; 
}

Edit
basename($file) to get filename from path but how to add _thumb.jpg?

  • 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-17T11:36:06+00:00Added an answer on June 17, 2026 at 11:36 am

    Don’t have much experience with PHP but using this as starting point, I get:

    $pattern = '/^.*\/(.*)$/'; // match everything after the last slash and store it in $1
    $replacement = '$1';
    $filename = preg_replace($pattern, $replacement, $file);
    
    $get_path = $file . '/thumbs/' . $filename;
    

    As I said, not much experience with PHP, but this should do it…

    A more easy way to do this, could be:

    1. Find the last / in $file
    2. Insert thumbs/ after it or replace it with /thumbs/
    3. Find the last . in the edited $file
    4. Insert _thumb after it

    You can find the postitions of / and . with the strrchr function (documented here).

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

Sidebar

Related Questions

I'm trying to load an image store in locally and then delete original file.
I need to upload an image file and generate a thumbnail for the uploaded
$thumbnail_url = 'http://img.youtube.com/vi/JaFfJN_iKdA/default.jpg'; function save_image_local($thumbnail_url) { //for save image at local server $filename =
I am trying to store an image uploaded by the user into the database
I have stored images from the net like this Documents/imagecache/domain1/original/path/inURI/foo.png Documents/imagecache/domain2/original/path/inURI/bar.png Documents/imagecache/... Documents/imagecache/... Now
I've managed to get the original filename of a photo stored in the asset-library
I'm looking to handle image extentions .jpg , .png , .gif , etc. Essentially,
Uploading files (images) via ajax multi-uploader (http://github.com/valums/file-uploader). Each uploaded file is saved in temp
Im unable to find out the correct path for inclusion of my Carrierwave image.
I want to basically make a simple picture upload, then change the first picture

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.