如何获取多个文件上传的单个文件链接

时间:2014-08-22 12:29:51

标签: php forms

我确实做过上传很多文件的代码。我现在要做的是在一次上传多个文件时保存每个文件事件的路径。我无法获得底部带代码的文件夹:

<?php
  $valid_formats = array("jpg", "png", "gif", "zip", "docx","zip","pdf");
  $max_file_size = 1024*100; 
  $path = "/uploads/$orderid/";
  if ( ! is_dir($path)) {
    mkdir($path);
  }
     $count = 0;

  if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
  foreach ($_FILES['content']['name'] as $f => $name) {     
    if ($_FILES['content']['error'][$f] == 4) {
       continue;
   }          
   if ($_FILES['content']['error'][$f] == 0) {               
      if ($_FILES['content']['size'][$f] > $max_file_size) {
          $message[] = "$name is too large!.";
          continue; // Skip large files
      }
      elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
         $message[] = "$name is not a valid format";
          continue; // Skip invalid file formats
     }
    else{ // No error found! Move uploaded files 
        if(move_uploaded_file($_FILES["content"]["tmp_name"][$f], $path.$name))
        $count++; // Number of successfully uploaded file

       }
     }
    }
     echo "<div>You have uploaded : ". $count."</div>";
    }

    $sql="INSERT INTO oz2ts_web_intake_files_folder (file_id, f_folder)
    VALUES
     ('$orderid', '$path')";


    ?>

1 个答案:

答案 0 :(得分:0)

请参阅HTML 5 multi file upload with PHP

的已接受答案

对于您,您的foreach循环将如下所示:

foreach ($_FILES['content'] as $file) { 

从这里开始,您可以将$file视为单个文件(例如,使其名称使用$file['name']