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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:08:22+00:00 2026-06-06T06:08:22+00:00

I have a problem here im trying to upload a file first time it

  • 0

I have a problem here im trying to upload a file

first time it is moving the filename from temp it its respective directory,

but again i try ot upload the aa different file with the same name it should rename the
first time uploaded file

with date_somefilename.csv and give the filename to its original state

for example a file test.csv ,im uploading it for first time it will upload to
corresponding directory as

test.csv,when i upload a different csv file with same name test.csv

I need to get the

test.csv (latest uploaded file)

06222012130209_test.csv(First time uploaded file)

The code is below

$place_file = "$path/$upload_to/$file_name";     



if (!file_exists('uploads/'.$upload_to.'/'.$file_name)) 
 {

move_uploaded_file($tmp, $place_file);  


}else{

 move_uploaded_file($tmp, $place_file); 
 $arr1 = explode('.csv',$file_name);
  $todays_date =  date("mdYHis");
   $new_filename = $todays_date.'_'.$arr1[0].'.csv';
  echo  $str_cmd = "mv " . 'uploads/'.$upload_to.'/'.$file_name . " uploads/$upload_to/$new_filename";
   system($str_cmd, $retval); 
} 
  • 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-06T06:08:24+00:00Added an answer on June 6, 2026 at 6:08 am

    See comments in code.

    $place_file = "$path/$upload_to/$file_name";     
    
    if (!file_exists($place_file)) {
        move_uploaded_file($tmp, $place_file);  
    } else {
        // first rename
        $pathinfo = pathinfo($place_file);
        $todays_date = date("mdYHis");
        $new_filename = $pathinfo['dirname'].DIRECTORY_SEPARATOR.$todays_date.'_'.$pathinfo['basename'];
        rename($place_file, $new_filename)
        // and then move, not vice versa
        move_uploaded_file($tmp, $place_file); 
    } 
    

    DIRECTORY_SEPARATOR is php constant. Value is ‘/’ or ‘\’, depending of operation system.

    pathinfo() is php function, that return information about path: dirname, basename, extension, filename.

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

Sidebar

Related Questions

I'm having a problem here trying to upload a file with powershell. What I'm
i have problem on my php file upload script , i am trying to
I have an interesting problem here I've been trying to solve for the last
Here is a problem I am trying to solve: I have an irregular shape.
I have a litte problem here. I want to join twice from the same
I am trying to simulate an asynchronous file upload using an iframe. Here is
Here is my problem. I upload a csv file containing two columns (student Number
I'm trying to use Uploadify for the first time. I have no issues with
I'm trying to upload an excel file. I have an ASP.NET test site on
Here's what I'm trying to do, and failing... I have a File model which

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.