0

I made a function which is successfully uploading [multiple] the files. But If I try to change the filename, the filename is getting changed but only last selected file is getting uploaded.

Here is my code.

<?php
    $files = $_FILES['userfile'];
    $dir = './uploads/';
    foreach ($files['name'] as $key => $value) {
        $direction = $dir . $_FILES['userfile']['name'][$key];
        move_uploaded_file($_FILES['userfile']['tmp_name'][$key], $direction);
    }
?>

Manage to do this

       $files = $_FILES['userfile'];
        $dir = './uploads/';
        foreach ($files['name'] as $key => $value) {

            $filename = $_FILES["userfile"]["name"][$key];

            $temp = explode(".", $filename);
            $newfilename = uniqid('',true).'.'.end($temp);
            $direction = $dir.$newfilename; 
            move_uploaded_file($_FILES['userfile']['tmp_name'][$key], $direction);
        }

problem was with the microtime()

2

1 Answer 1

0

Try This Code

//load date helper 
$this->load->helper('date');

$files = $_FILES['userfile'];
        $dir = './uploads/';
        foreach ($files['name'] as $key => $value) {

            $filename = $_FILES["userfile"]["name"][$key];

            $temp = explode(".", $filename);
            //
            $file_tempname = date('Y-m-d H:i:s');
            //
            $newfilename = $file_tempname.'.'.end($temp);

            $direction = $dir.$newfilename; 
            move_uploaded_file($_FILES['userfile']['tmp_name'][$key], $direction);
        }
Sign up to request clarification or add additional context in comments.

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.