I am trying to loop through an array of variables of type '$_FILES' posted from a form and process each image and store directories
The code is
if(isset($_POST['travsubli'])){
$date=Date('Y-m-d');
$uname=substr($utravlastname,0,5).substr($utravphone,5,10);
$destin=str_replace(array(" ","/","."),"-",$_POST['Destination']);
if(!is_dir("images/userimages/travelphotos")) {mkdir("images/userimages/travelphotos");}
if(!is_dir("images/userimages/travelphotos/$uname")){mkdir("images/userimages/travelphotos/$uname");}
echo "Check : ".$_FILES['TourPhoto1']['name']."<br>";
$photosarray=array($_FILES['TourPhoto1']['name'],$_FILES['TourPhoto2']['name'],$_FILES['TourPhoto3']['name'],$_FILES['TourPhoto4']['name'],$_FILES['TourPhoto5']['name'],$_FILES['TourPhoto6']['name']);
$pai=1;
foreach($photosarray as $pha){
$ext=pathinfo($pha,PATHINFO_EXTENSION);
if(!empty($ext)){
$newphotoname="Travelogue-Photo-$destin-$pai.$ext";
$newphotopath="images/userimages/travelphotos/$uname/$newphotoname";
if(move_uploaded_file($pha,$newphotopath)){
echo "Photo Successfully Uploaded !<br>";
}else{echo "Something went wrong with Photo Upload !<br>"; $e=error_get_last();echo $e['message']."<br>";}
}
$TourPhoto="TourPhoto$pai";
$$TourPhoto=$newphotoname;
echo $pha."->$TourPhoto->".$$TourPhoto.$pai."<br>";
$pai++;
}
My question or rather propblem is,
Move_uploaded_file does not work.
I presume it is because I am using $_FILES['variable']['name'] instead of $_FILES['variable']['tmp_name'] in the move_uploaded_file command.
Am I right in my diagnosis ? If so, what should be done ? Because, I have assigned 'name' parameter in the array to loop. How do I undo it to 'tmp_name' inside the loop ? Or is there any other better alternative ?