I am unable to upload the files using php. I am using a common array for a control as media[] here,and then using for loop I am uploading. here is my code so far:
<form class="form-horizontal" method="post" action="gallery.php">
<fieldset>
<div class="control-group">
<label class="control-label" for="typeahead">Select File</label>
<div class="controls">
<input class="input-file uniform_on" id="media[]" name="media[]" type="file">
</div>
</div>
<div class="control-group">
<label class="control-label" for="typeahead">Select File</label>
<div class="controls">
<input class="input-file uniform_on" id="media[]" name="media[]" type="file">
</div>
</div>
<div class="control-group">
<label class="control-label" for="typeahead">Select File</label>
<div class="controls">
<input class="input-file uniform_on" id="media[]" name="media[]" type="file">
</div>
</div>
<div class="control-group">
<label class="control-label" for="typeahead">Select File</label>
<div class="controls">
<input class="input-file uniform_on" id="media[]" name="media[]" type="file">
</div>
</div>
<div class="control-group">
<label class="control-label" for="typeahead">Select File</label>
<div class="controls">
<input class="input-file uniform_on" id="media[]" name="media[]" type="file">
</div>
</div>
<!--<input type="text" class="span6 typeahead" id="city" name="city" required >
<p class="help-block">Example : Nalasopara , Vasai road ..</p>-->
<div class="form-actions">
<button type="submit" name="submit" id="submit" class="btn btn-primary">Save changes</button>
<button type="reset" class="btn">Cancel</button>
</div>
</fieldset>
</form>
and:
<?php
if(isset($_POST["submit"]))
{
//$media=$_POST["media"];
//$media=$_FILES['media']['name'];
$type="";
$count=count($_POST["media"]);
//echo "count: ".$count."<br>";
for($i=0;$i<$count;$i++)
{
$media1=$media[$i];
if($media1=="")
{
}
else
{
$ext = pathinfo($media1, PATHINFO_EXTENSION);
if($ext=="jpg"||$ext=="JPEG"||$ext=="JPG"||$ext=="png"||$ext=="gif"||$ext=="GIF")
{
$type="image";
//echo $type;
}
else if($ext=="flv"||$ext=="mp4"||$ext=="wma"||$ext=="3gp"||$ext=="mpeg"||$ext=="mkv"||$ext=="avi")
{
$type="video";
}
$filename = ("gallery");
if (file_exists($filename))
{
move_uploaded_file($_FILES["media"]["tmp_name"][$i], "$filename/".$_FILES["media"]["name"][$i]);
}
else
{
mkdir("gallery");
move_uploaded_file($_FILES["media"]["tmp_name"][$i], "$filename/".$_FILES["media"]["name"][$i]);
}
}
}
//header('Location: gallery.php');
}
?>
folder is getting created but files are not getting uploaded,kindly help.
Add
enctype='multipart/form-data'
in your form.See this link
Edit: