dongyan3018 2016-11-30 06:57
浏览 9

无法在php中上传多个文件

I have create a multiple file upload functionality in PHP. when i try to upload files i select 15 files at a time when request is processed only first four files are stored in db and all 15 files are uploaded in directory every time.

i have also checked the PHP.ini file the max file upload limit is 50 pre request and post max size is 5M. still cnt find any solution to the problem.

why record is saved forfirst four file only.

if($_POST['submit']== 'Upload_picture')
    {
        //echo "<pre>";     print_r($_FILES['upload_picture']['name']);
        //die;

        $album_title = $_GET['name'];
        $album_id = $_GET['album'];
        $album_dir = "../images/album/$album_title/"; #album path root directory
        $db_album_dir = "images/album/$album_title/"; #batadase album path root directory
        $error = array();
        $extension = array('jpg','gif','png','jpeg');
        foreach($_FILES['upload_picture']['tmp_name'] as $key => $tmp_name){
            $file_name = $_FILES['upload_picture']['name'][$key];
            $file_tmp = $_FILES['upload_picture']['tmp_name'][$key];
            $ext = pathinfo($file_name, PATHINFO_EXTENSION);
            $new_filename = rand().".".$ext; #changing name
            if(in_array($ext,$extension))
            {
                if(move_uploaded_file($file_tmp= $_FILES['upload_picture']['tmp_name'][$key],"$album_dir$new_filename"))
                {
                # insert record database

                    $values = [
                    'album_id' =>$album_id,
                    'image_name' => $new_filename,
                    'album_name' => $album_title,
                    'image_path' => $db_album_dir.$new_filename,
                    'uploaded_date' => date("Y/m/d h:i:s a")
                    ];
                    include_once "action_page.php";
                    $tablename = 'album_picture';
                    $abc = new Demo();
                    $res = $abc->insert($tablename,$values);
                    unset($abc);
                    $_SESSION['upload_success'] = "Files Uploaded succesfully"; 
                    header("location:../upload_album.php?album=$album_id&name=$album_title");

                }
                else
                {
                        $_SESSION['upload_error'] = "Something went wrong, files cannot be uploaded"; 
                }

            }
            else
            {
                $_SESSION['upload_warning'] = "Please upload file"; 
                header("location:../upload_album.php?album=$album_id&name=$album_title");
            }
        }//EOF FROEACH
  • 写回答

1条回答 默认 最新

  • dongzhong5833 2016-11-30 07:03
    关注

    Your input field for file should be something like this:

     <input type="file" id="file" name="name[]" multiple />
    
    if(isset($_FILES['upload_picture']['name']))
        {
            $file_name_all="";
            for($i=0; $i<count($_FILES['upload_picture']['name']); $i++) 
            {
                   $tmpFilePath = $_FILES['upload_picture']['tmp_name'][$i];    
                   if ($tmpFilePath != "")
                   {    
                       $path = "propertyimages/"; // create folder 
                       $name = $_FILES['upload_picture']['name'][$i];
                      $size = $_FILES['upload_picture']['size'][$i];
    
                       list($txt, $ext) = explode(".", $name);
                       $file= time().substr(str_replace(" ", "_", $txt), 0);
                       $info = pathinfo($file);
                       $filename = $file.".".$ext;
                       if(move_uploaded_file($_FILES['upload_picture']['tmp_name'][$i], $path.$filename)) 
                       { 
                          $file_name_all.=$filename."*";
                       }
                 }
            }
             $filepath = rtrim($file_name_all, '*'); 
             $tablename = 'album_picture';
             $abc = new Demo();
             $res = $abc->insert($tablename,$values);
             unset($abc);
            }
            else
        {
            $filepath="";
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么