-4

I am using following code for uploading multiple files. i don't know whether this code is right or wrong because some of my users are getting syntax error in this page. So, i want to check this code. please help me.

<?php
if(!empty($_FILES['MyPhoto']['name'])){
    $Photos=$_FILES['MyPhoto']['name'];
    $valid_formats = array("jpeg", "jpg", "png");
    $Vars=array("A","B","C","D");
    $PicsArray=array();
    $x="0";
    $y="0";
    $Id="some_variable";

        foreach($Photos as $Pics){
            $PicType= pathinfo($Pics, PATHINFO_EXTENSION);
            if(in_array($PicType, $valid_formats)) {
                $PicName=$Id.$Vars[$y];
                $tmpFilePath = $_FILES['MyPhoto']['tmp_name'][$x];
                $newFilePath = "./MyPics/" .$PicName.".".$PicType;
                $newFilePath1 = "./Admin/MyPics/" .$PicName.".".$PicType;
                $newFilePath2 = "./Admin/NewPics/" .$PicName.".".$PicType;
                if(move_uploaded_file($tmpFilePath, $newFilePath)) {
                     copy($newFilePath, $newFilePath1);
                     copy($newFilePath, $newFilePath2);
                    }
                $y++;
                }
            $x++;
        }
    }
?>

i have tested in http://phpfiddle.org/. it is showing following error:

You input disabled function(s) by PhpFiddle : move_uploaded_file($tmpFilePath, $newFilePath)), copy($newFilePath, $newFilePath1), copy($newFilePath, $newFilePath2)

  • that just means phpfiddle does not support file uploads, its not saying anything is wrong with your code. what are the errors on YOUR site? –  Aug 02 '17 at 22:18
  • my customers are getting syntax error in this page. But this page has along with some other code also. but i thought this code might be problem. that's why i brought it here. – yaseen ahmed Aug 02 '17 at 22:23
  • 1
    what syntax errors? we are not psychic –  Aug 02 '17 at 22:24
  • 1
    You will have to show the other code for us to know. The part you posted, does not have any syntax error... – Yolo Aug 02 '17 at 22:29
  • because of my customers are saying that browser says "syntax error". – yaseen ahmed Aug 02 '17 at 22:29
  • I quit, have a nice day –  Aug 02 '17 at 22:31

1 Answers1

0

This question is already answered here.

Though it is for uploading with one input, it can be modified to upload with multiple inputs, too.

UPDATE

HTML:

<input type="file" name="img[]">
<input type="file" name="img[]">

PHP:

foreach($_FILES["img"]["tmp_name"] as $key=>$tmp_name){
     //the code on the link I shared.
}
TheCleverIdiot
  • 412
  • 4
  • 19