dongweishi2028 2014-08-22 12:29
浏览 43

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

I did did code to upload many files. What I want to do now is to save the path for each file event when many files are uploaded at once. I am unly able to get the folder with the code at the bottom:

<?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条回答 默认 最新

  • doupu1957 2014-08-22 12:46
    关注

    See accepted answer of HTML 5 multi file upload with PHP

    For you, your foreach loop would look like:

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

    From here you can treat $file as it was single file (for example, to get it's name use $file['name'])

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值