0

I am using the code bellow to upload a file using php and inserting file name into database. Actually I want to rename of file on uploading and want to insert new renamed name into database. I know how to insert name into database but I don't know how to rename uploaded file name. Please help. I am using code bellow:

$target = "uploads/"; 
$target = $target . basename( $_FILES['uploaded']['name']); 

move_uploaded_file($_FILES['uploaded']['tmp_name'], $target);
$add_file = $_FILES['uploaded']['name'];

Thank you so much..

2 Answers 2

2

Is this what you are looking for?

<?php
    rename("/tmp/uploaded_file.txt", "/home/user/login/uploaded/67A7466B576.txt");
?>

So new code will be:

$target = "uploads/"; 
$target = $target . basename( $_FILES['uploaded']['name']); 
rename($_FILES['uploaded']['tmp_name'], $target);
$add_file_to_db = $target;
Sign up to request clarification or add additional context in comments.

1 Comment

I want to insert renamed name into database so what variable I will use to insert into database ? $add_file_to_db ?
0

This might be helpful for you:

$uploaded_file = time()."__".$_FILES['uploaded']['name'];

This simply adds time before the name of the file.

Example:

If I uploaded the AnalysisReport.doc file, then it simply becomes like 1354173106__AnalysisReport.doc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.