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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:05:20+00:00 2026-05-13T08:05:20+00:00

I use Windows and I display a file extention. When I upload an image

  • 0

I use Windows and I display a file extention.

When I upload an image file with PHP, a image name of image1_big.jpg becomes image1_big.jpg.jpg.

And image2.gif becomes image2.gif.gif.

I don’t want to turn off file extension.

How can I avoid this problem?

function addProduct(){
    $data = array( 
        'name' => db_clean($_POST['name']),
        'shortdesc' => db_clean($_POST['shortdesc']),
        'longdesc' => db_clean($_POST['longdesc'],5000),
        'status' => db_clean($_POST['status'],8),
        'class' => db_clean($_POST['class'],30),
        'grouping' => db_clean($_POST['grouping'],16),
        'category_id' => id_clean($_POST['category_id']),
        'featured' => db_clean($_POST['featured'],5),
        'price' => db_clean($_POST['price'],16)

    );

    if ($_FILES){
        $config['upload_path'] = './images/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '200';
        $config['remove_spaces'] = true;
        $config['overwrite'] = false;
        $config['max_width']  = '0';
        $config['max_height']  = '0';
        $this->load->library('upload', $config);    
        if (strlen($_FILES['image']['name'])){
            if(!$this->upload->do_upload('image')){
                $this->upload->display_errors();
                exit();
            }
            $image = $this->upload->data();
            if ($image['file_name']){
                $data['image'] = "images/".$image['file_name'];
            }
        }
        if (strlen($_FILES['thumbnail']['name'])){
            if(!$this->upload->do_upload('thumbnail')){
                $this->upload->display_errors();
                exit();
            }
            $thumb = $this->upload->data();
            if ($thumb['file_name']){
                $data['thumbnail'] = "images/".$thumb['file_name'];
            }
        }
    }
    $this->db->insert('omc_products', $data);   

    $new_product_id = $this->db->insert_id();
...
...
  • 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-13T08:05:21+00:00Added an answer on May 13, 2026 at 8:05 am

    if you feel you need to, you can just strip the file extention. However, i would go with BalusC’s comment that it is not the correct behavior for PHP in general:

    $filename = substr($filename_passed_to_upload, 0, (strlen($filename_passed_to_upload) - 4));
    

    or, more rigourously:

    $temp = explode(".", $filename_passed_to_upload);
    $new_filename = $temp[0]; 
    // be careful, this fails when the name has a '.' in it other than for the extention
    // you'll probably want to do something with a loop with $temp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to have my VBScript display the Windows Save As dialog box, but
Hi does anyone know I can display the icon of a file that has
I'm attempting to use the lwjgl library and I'm starting from scratch on a
I'm writing an application that loads in records from an XML file and uses
As we know, in windows system, we can set locale language for non-Unicode programs
I have been trying to use HG convert to migrate a local CVS repository
I was contemplating moving to a version control system at work, but the learning
I want to hide the .py extension of a Python script loaded in a
i have a problem with wxpython and his rich text control, when I try
I just upgraded to the beta 2 of Crystal Reports for Visual Studio 2010

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.