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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:37:09+00:00 2026-05-21T06:37:09+00:00

Hello everyone I am completely stuck with this problem. I want add the name

  • 0

Hello everyone I am completely stuck with this problem.

I want add the name of a file I changed using the string “rename” function in codeigniter to an array and then send that array to a model where I can extract it and add to it my database.

However when I do this the value added in my database for the file name always comes as ‘1’.

Here is my code, in it I am uploaded and file.

This is part of the controller class with the file name changing and adding to the array

        $data = array('upload_data' => $this->upload->data()); // Get the file from the form userfile information
        $file = $data['upload_data']['file_name'];

        //hacky name generator
        $randomstring = random_string('alnum', 4);
        $filenew = rename($dir . $file, $dir . $id . '_' . $randomstring . '.jpg'); //basic php rename call, rename my upload now that upload finished

        // this array is all the other values from my form fields
        $data = array($this->input->post('comment'), $filenew);

        $configB['image_library'] = 'gd2'; // this code begins the thumbnail making process, from user guide
        $configB['source_image'] = $filenew;//$dir . $id.'.jpg'; // I am using $id for image name, which is my users id, comes from the session
        $configB['create_thumb'] = FALSE;
        $configB['maintain_ratio'] = TRUE;
        $configB['width'] = 300;
        $configB['height'] = 300;
        $this->image_lib->initialize($configB); 
        $this->image_lib->resize();

        $this->load->model('membership_model'); 
        // run my model which saves all this to the database, image name also ($filenew)   
        if($query = $this->membership_model->create_post($id,$data)) 
        {
            $data = array('upload_data' => $this->upload->data());
            $data['filename'] = $filenew; 
            $this->load->view('post_success_view', $data);

        }

Here is the model

function create_post($id, $data) 
{
    //get data from array
            $content = $data[0];
    $filename = $data[1]; 

    // update database to track a new post.
    $new_post_insert_data = array(
        'content' => $content,
        'beer_down' => 0,
        'beer_up' => 0,
        'user_name' => $this->session->userdata('username'),
        'account_id' => $this->session->userdata('userid'),
        'file_name' => $filename
        );

    $insert_post = $this->db->insert('post', $new_post_insert_data);
    return $insert_post;    
}

Thank you in advanced if you can help me out been stuck here for hours.

  • 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-21T06:37:09+00:00Added an answer on May 21, 2026 at 6:37 am

    rename() changes the name of a system resource, and returns a Bool for success. When you cast that boolean true to a string, you get “1”. If you want to store the name in the DB, you should set a variable ie:

    $new_name = $dir . $id . '_' . $randomstring . '.jpg';
    

    then call rename:

    rename($dir . $file, $new_name);
    

    and use the $new_name to insert in the database.

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

Sidebar

Related Questions

THIS PROBLEM IS NOW SOLVED. THANK YOU TO EVERYONE WHO REPLIED. Hello, I am
hello everyone im trying to create this tweak that copies a file from one
hello everyone i want validate the type of file being uploaded on sever to
hello everyone I found this function in Kernel of the Linux: inline task_t *context_switch(task_t
Hello everyone i need to convert this code to a function with 2 parameters
Hello everyone I am trying to resize an image of 700kb with imagecreatefromjpeg. This
Hello everyone I am new to blackberry and I want a textfield that scroll
Hello Everyone, I am experiencing a strange problem when deploying a Rails 3.1 application
Hello everyone I want to ask a question about including guards in C programming.
Hello everyone i have a problem in my application. The check in my check

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.