-2
    <form action="" method="post" enctype="multipart/form-data">
    <input type="" name="fname" />
    <input type="file"  name="filepath" id="filepath"/><br><br>
    <input type="submit" name="SubmitButton" value="Submit"/>
    </form>

 -----------------php-----------------------------------   
    $newname=$_POST['fname'];
    $target_dir = 'uploads/reports/';
    $filename=$_FILES["filepath"]['name'];
    $ext = pathinfo($filename, PATHINFO_EXTENSION);

    $_FILES["filepath"]['name']=$newname.".".$ext;

    $target_file = $target_dir . basename($_FILES["filepath"]['name']);
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
    $_FILES["tmp_name"]=$newname;
    echo $target_file;
    move_uploaded_file($_FILES["filepath"]["tmp_name"], $target_file);

    } 

i need to upload multiple files (excel,word documents,images) from single input(i mean , we could select multiple files when we browse) to database , this code is work only for one file.and rename that file as $newnam(1),$newname(2).... like that

SL cLaY
  • 5
  • 4
  • 1
    It's not recommended uploading files to the database, you probably want to upload them to the server and just store the image path into the database. – Boian Ivanov Sep 13 '17 at 06:15
  • 1
    This question is better answered here. [enter link description here](https://stackoverflow.com/questions/2704314/multiple-file-upload-in-php) – aman Sep 13 '17 at 06:15
  • 1
    Possible duplicate of [Multiple file upload in php](https://stackoverflow.com/questions/2704314/multiple-file-upload-in-php) – SherylHohman Sep 13 '17 at 06:18
  • This question is better answered here: [Multiple file upload in php](https://stackoverflow.com/questions/2704314/multiple-file-upload-in-php) – aman Sep 13 '17 at 06:19
  • @BoianIvanov but im designing a interface for input project details and project files report files to the server , and im trying to display and download that files wen we needed, – SL cLaY Sep 13 '17 at 06:27
  • @SLcLaY you can still achieve this by saving the files in the server, and storing the file path in the database. When you need to present the file to the user, you give him the directory and he can access the needed file. – Boian Ivanov Sep 13 '17 at 06:42
  • @BoianIvanov now see the code , from this, only i can save one file and rename it, i want store multiple files store like that and renamed it – SL cLaY Sep 13 '17 at 08:40
  • @jeger now i uploaded again whaat i have done please refer the code now – SL cLaY Sep 13 '17 at 09:06

1 Answers1

0

For this you have to provide the input name as an array and provide the multiple attribute like:

<input type="file"  name="filepath[]" id="filepath" multiple />

and you can get its content using:

$_FILES['filepath']  // It returns an array
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59