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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:18:45+00:00 2026-06-15T17:18:45+00:00

i build function to upload zip files but when user upload file two times

  • 0

i build function to upload zip files but when user upload file two times it didnt delete the first uploaded file but added increment number to the file name (( file.zip,file1.zip,file2.zip,,,etc )

so i want to tell the function when the user uploaded the same file name delete the first file and upload this second file or replace it … anyone help me how to do that…

/**
 * change book source file
 * 
 * @param integer $book_id 
 */
public function upload_book_zip($book_id) {
    $vars = array();
    $vars['upload_path'] = PUBPATH . 'global/modules/bookstore/files/books_source_file/';
    $vars['allowed_types'] = 'zip';
    $vars['max_size'] = '30720';
    $vars['book_id'] = $book_id;

    $book = $this->d_book->find_by_id($book_id);
    if (isset($_POST['submit'])) {
        $file_name = $this->upload($vars);
        if ($file_name === NULL) { // error happens while uploading file
            $vars['upload_errors'] = $this->upload->display_errors("<p class='notification n-error'>", "</p>");
        } else {
            $this->d_book->update_one_field($book_id, 'bo_path_zip', $file_name);
            $this->session->set_flashdata('success_msg', lang('file_uploaded'));
            redirect('bookstore/admin_d_book/');
        }
    } else {
        $vars['upload_errors'] = NULL;
    }

    if ($book->bo_path_zip) { // load cover image
        $vars['file_path'] = base_url() . 'global/modules/bookstore/files/books_source_file/' . $book->bo_path_zip;
    } else {
        $vars['file_path'] = NULL;
    }
    $vars['controller_name'] = 'admin_d_book';
    $this->view('bookstore/admin/change_zip_file', $vars);
}

    /**
 * 
 * @param array $config the configuration array
 * @return string
 * 
 */
private function upload($config) {
    $this->load->library('upload', $config);

    if (!$this->upload->do_upload("file")) {
        return $uploadData['file_name'] = NULL;
    } else {
        $uploadData = $this->upload->data();
        log_message('debug', 'file has been uploaded ok - file name is ' . $uploadData['file_name']);
        return $uploadData['file_name'];
    }
}
  • 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-15T17:18:46+00:00Added an answer on June 15, 2026 at 5:18 pm

    you can do that by adding

    $vars['overwrite'] = TRUE;
    

    better check File upload library

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

Sidebar

Related Questions

I'm trying to build a function that will remove all the files that start
I'm using telerik radUpload control to build a page like gmail file upload, I
I'm attempting to build an extremely simple, but cross-browser compatible, asynchronous file uploader, as
I am wondering whether there is a way to upload a zip file to
I use blue-imp jquery.fileupload basic plug int to build my own multiple file upload
I am trying to upload a file to a ftp server using libcurl but
I've built a form to upload images, and processed with Prototype/PHP. $('image_upload').observe('submit', function() {
How can I build a function slice(x, n) which would return a list of
How does one build a function that can set an arbitrary value within a
I'd like to build a function that returns false if it's been called less

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.