I have a form and user can upload multiple files. I am trying to get the files from files[] and return values as variables. This is the first time I am dealing with image uploads and I am pretty much stuck. Your help is much appreciated. Sincerely,
Following is my file upload form elements.
<div class="section">
<label for="file1" class="field-label">
Upload image - <span class="small-text fine-grey"> (ONLY JPG : PNG : PDF) </span>
</label>
<label class="field prepend-icon file">
<span class="button btn-primary"> Choose File </span>
<input type="file" class="gui-file" name="file[]" required id="file1"
onChange="document.getElementById('uploader1').value = this.value;">
<input type="text" class="gui-input" id="uploader1" placeholder="no file selected" readonly>
<span class="field-icon"><i class="fa fa-upload"></i></span>
</label>
</div><!-- end section -->
<div class="section">
<label for="file1" class="field-label">
Upload another image - <span class="small-text fine-grey"> (ONLY JPG : PNG : PDF) </span>
</label>
<label class="field prepend-icon file">
<span class="button btn-primary"> Choose File </span>
<input type="file" class="gui-file" name="file[]" required id="file2"
onChange="document.getElementById('uploader2').value = this.value;">
<input type="text" class="gui-input" id="uploader2" placeholder="no file selected" readonly>
<span class="field-icon"><i class="fa fa-upload"></i></span>
</label>
</div><!-- end section -->
So far I have created the following and I don't think it is working.
Following is enabled on my form. enctype="multipart/form-data" Following is part of my process .php where I send form values.
// Here is the updated code***
$file = $_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";
$filecount = count($file);
for ($f=0; $f < $filecount; $f++){
$rand = rand(1000,100000)."-";
if (move_uploaded_file($file_loc[$f],$folder.$rand.$file[$f]) ){
//I need maximum 2 files uploaded. I guess name should be something else instead of file[0,1] such as finalname[0];
$img_url=$file[0];
$img_urla=$file[1];
}