Solved

PHP File Upload Issue

Posted on 2013-11-08
11
906 Views
Last Modified: 2013-11-08
I'm having problems getting a file to successfully upload within my page.  I can upload a file on my server without any issues on a test page that has nothing but a file upload.  However when I include it within my actual page the file never gets uploaded.  

I believe it's because it's an array within an array?  I wasn't quite sure how to do it, but trial and error isn't working.

Here it is on jsfiddle:
http://jsfiddle.net/gallitin/m4A4r/

HTML
<div id="questions" style="font-family:myriad-pro-condensed,sans-serif;margin-bottom:10px;">
                    <!--This will hold the question -->
                    </div>
                    <p><button id="addQuestion" style="background:url('img/addquestion.png');border:0;height:28px;width:140px;float:right;">Add Question</button></p>
                    <div id="masterQuestion">
                        <!-- This is the hidden master content used for cloning -->
                        <div class="questionChanger" style="float:right;">
                            <select name="question[*][type]" class="dynamic" style="color: #808080;font-family: myriad-pro-condensed,sans-serif;font-size:14px;width:150px;padding:5px;">
                                <option value="type1">Free Text</option>
                                <option value="type2">Multiple Choice</option>
                                <option value="type3">Yes or No</option>
                            </select>
                        </div>

                        <div id="type1" class="questionSet">
                            <h9>Question</h9><br>
                            <div id="articlesep" style="margin-top:15px;margin-bottom:10px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <input type="text" class="dynamic" name="question[*][question]" placeholder="QUESTION" style="padding:2px 2px 2px 15px;width:600px;" />
                            <div id="articlesep" style="margin-bottom:15px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <div id="mediaupload">
                                <div id="uploadbtn" style="float:left;">
                                    
                                </div>
                                <div id="ortxt" style="float:left;margin-top:45px;margin-left:30px;">
                                    <h9>OR</h9> <input type="text" placeholder="LINK TO URL OF IMAGE OR VIDEO" class="dynamic" name="question[*][medialink]" style="padding:2px 2px 2px 15px;width:315px;margin-left:30px;"/>
                                </div>
                                <div id="clearfix"></div>
                            </div>
                            <label for="file">Filename:</label>
                            <input type="file" name="file" id="file"><br>
                        </div>

                        <div id="type2" class="questionSet">
                            <h9>Question</h9><br>
                            <div id="articlesep" style="margin-top:15px;margin-bottom:10px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <input type="text" class="dynamic" name="question[*][question]" placeholder="QUESTION" style="padding:2px 2px 2px 15px;width:600px;" />
                            <div id="articlesep" style="margin-bottom:15px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <div id="mediaupload">
                                <div id="uploadbtn" style="float:left;">
                                
                                </div>
                                <div id="ortxt" style="float:left;margin-top:45px;margin-left:30px;">
                                    <h9>OR</h9> <input type="text" class="dynamic" placeholder="LINK TO URL OF IMAGE OR VIDEO" name="question[*][medialink]" style="padding:2px 2px 2px 15px;width:315px;margin-left:30px;"/>
                                </div>
                                <div id="clearfix"></div>
                            </div>
                            <div id="articlesep" style="margin-bottom:15px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <input type="text" class="dynamic" name="question[*][answer1]" placeholder="ANSWER 1" style="padding:2px 2px 2px 15px;width:600px;" />
                            <input type="text" class="dynamic" name="question[*][answer2]" placeholder="ANSWER 2" style="padding:2px 2px 2px 15px;width:600px;" />
                            <input type="text" class="dynamic" name="question[*][answer3]" placeholder="ANSWER 3" style="padding:2px 2px 2px 15px;width:600px;" />
                            <input type="text" class="dynamic" name="question[*][answer4]" placeholder="ANSWER 4" style="padding:2px 2px 2px 15px;width:600px;" />
                            <input type="text" class="dynamic" name="question[*][answer5]" placeholder="ANSWER 5" style="padding:2px 2px 2px 15px;width:600px;" />
                        </div>

                        <div id="type3" class="questionSet">
                            <h9>Question</h9><br>
                            <div id="articlesep" style="margin-top:15px;margin-bottom:10px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <input type="text" class="dynamic" name="question[*][question]" placeholder="QUESTION" style="padding:2px 2px 2px 15px;width:600px;" />
                            <div id="articlesep" style="margin-bottom:15px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <div id="mediaupload">
                                <div id="uploadbtn" style="float:left;">
                                
                                </div>
                                <div id="ortxt" style="float:left;margin-top:45px;margin-left:30px;">
                                    <h9>OR</h9> <input type="text" class="dynamic" placeholder="LINK TO URL OF IMAGE OR VIDEO" name="question[*][medialink]" style="padding:2px 2px 2px 15px;width:315px;margin-left:30px;"/>
                                </div>
                                <div id="clearfix"></div>
                            </div>
                        </div>
                    </div>

Open in new window


jquery
    $(document).ready(function() {

        //set up the 'Add New Question' button
        $('#addQuestion').click(function(e){
            //prevent the button from submitting the form
            e.preventDefault();

            //get the new question number
            var questionNumber = $('.question').length + 1;

            //clone the master questionChanger and 'type1' question (we need to remove the ID from the questionType - we don't need it)
            var questionChanger = $('#masterQuestion .questionChanger').clone(true);
            var questionType = $('#type1').clone().removeAttr('id');

            //create a new wrapper for the new question, set the question number (used later), add a class, and add the new content to it
            var newQuestion = $('<div>').data('qNum', questionNumber).addClass('question').append(questionChanger, questionType);

            //now loop through the '.dynamic' elements so we can change the name
            $('.dynamic', newQuestion).each(function() {
                //get the old dummy name
                var oldName = $(this).attr('name');

                //replace the dummy text (*) with the question number
                $(this).attr('name', oldName.replace('*', questionNumber));
            })

            //add the new question to the #questions DIV
            newQuestion.appendTo('#questions');
        });


        //set up the 'Question Type' changer
        $('.questionChanger select').change(function() {
            //what type of question are we cloning (match the values of the dropdown to the IDs of the master question types)
            var newQuestionType = $('#' + $(this).val()).clone().removeAttr('id');

            //get the question number (this time from the data-qNum attribute)
            var questionNumber = $(this).parents('.question').data('qNum');

            //loop through the new question and change the name of all the '.dynamic' elements
            $(newQuestionType).find('.dynamic').each(function(){
                //get the old dummy name
                var oldName = $(this).attr('name');

                //replace the dummy text (*) with the question number (this time from the data-qNum attribute)
                $(this).attr('name', oldName.replace('*', questionNumber));
            })

            //now add the new question type
            $(this).parents('.question').find('.questionSet').html(newQuestionType);
        });

    });

Open in new window

0
Comment
Question by:N R
  • 5
  • 4
  • 2
11 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39634013
when I include it within my actual page...
Does that mean that the PHP upload script works correctly by itself and only fails when jQuery is involved?
0
 
LVL 11

Author Comment

by:N R
ID: 39634028
@Ray - yes that's correct.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39634202
How does this get submitted?  I can't find a <form> tag.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 11

Author Comment

by:N R
ID: 39634215
Yes the form tags are above and below the code I posted above.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39634259
Could you please post the entire code set?  I'd like to install it on my server and see if I can find the issues.  Thanks, ~Ray
0
 
LVL 11

Author Comment

by:N R
ID: 39634314
Sure.

The index:
<script>
    $(function() {

        var leftPosInfo = $("<div>", {
            "class" : "sliderValue",
            text : "1"
        });

        $( "#pointslider" ).slider({
            range: false,
            min: 1,
            max: 500,
            values: [ 0],
            slide: function( event, ui ) {
                $( "#amount" ).val( "" + ui.values[ 0 ] );
                leftPosInfo.text(ui.values[ 0 ]);
            }
        });

        $(".ui-slider-handle").eq(0).append(leftPosInfo);
        $( "#amount" ).val( "" + $( "#pointslider" ).slider( "values", 0 ));
    });
</script>
<script>
    $(function() {
        $( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
    });
</script>
<script>
    $(document).ready(function() {

        //set up the 'Add New Question' button
        $('#addQuestion').click(function(e){
            //prevent the button from submitting the form
            e.preventDefault();

            //get the new question number
            var questionNumber = $('.question').length + 1;

            //clone the master questionChanger and 'type1' question (we need to remove the ID from the questionType - we don't need it)
            var questionChanger = $('#masterQuestion .questionChanger').clone(true);
            var questionType = $('#type1').clone().removeAttr('id');

            //create a new wrapper for the new question, set the question number (used later), add a class, and add the new content to it
            var newQuestion = $('<div>').data('qNum', questionNumber).addClass('question').append(questionChanger, questionType);

            //now loop through the '.dynamic' elements so we can change the name
            $('.dynamic', newQuestion).each(function() {
                //get the old dummy name
                var oldName = $(this).attr('name');

                //replace the dummy text (*) with the question number
                $(this).attr('name', oldName.replace('*', questionNumber));
            })

            //add the new question to the #questions DIV
            newQuestion.appendTo('#questions');
        });


        //set up the 'Question Type' changer
        $('.questionChanger select').change(function() {
            //what type of question are we cloning (match the values of the dropdown to the IDs of the master question types)
            var newQuestionType = $('#' + $(this).val()).clone().removeAttr('id');

            //get the question number (this time from the data-qNum attribute)
            var questionNumber = $(this).parents('.question').data('qNum');

            //loop through the new question and change the name of all the '.dynamic' elements
            $(newQuestionType).find('.dynamic').each(function(){
                //get the old dummy name
                var oldName = $(this).attr('name');

                //replace the dummy text (*) with the question number (this time from the data-qNum attribute)
                $(this).attr('name', oldName.replace('*', questionNumber));
            })

            //now add the new question type
            $(this).parents('.question').find('.questionSet').html(newQuestionType);
        });

    });
</script>
            <form action="submit.php" method="post" enctype="multipart/form-data">
                <div id="leftcontent" style="width:280px;background:#fff;margin-right:20px;float:left;padding:10px;">
                    <input type="text" placeholder="TITLE" name="title" style="padding:2px 2px 2px 15px;width:260px;"/>
                    <div id="articlesep" style="margin-bottom:5px;">
                        <img src="img/s1sep.png" style="width:280px;height:1px;"/>
                    </div>
                    <textarea placeholder="DESCRIPTION" name="description" style="height:75px;width:260px;padding:2px 2px 2px 15px;"></textarea>
                    <div id="articlesep">
                        <img src="img/s1sep.png" style="width:280px;height:1px;margin-bottom:85px;margin-top:10px;"/>
                    </div>
                    <div id="pointslider" style="padding:0;width:240px;margin-left:20px;height:5px;color:#47afc5;background:#47afc5;border:0;"></div>
                    <input type="hidden" id="amount" name="amount"/>
                    <div id="articlesep" style="margin-top:15px;margin-bottom:10px;">
                        <img src="img/s1sep.png" style="width:280px;height:1px;"/>
                    </div>
                    <input type="text" id="datepicker" name="enddate" placeholder="DATE" style="padding:2px 2px 2px 15px;width:260px;"/>
                    <div id="articlesep">
                        <img src="img/s1sep.png" style="width:280px;height:1px;"/>
                    </div>
                    <div id="publishsurvey" style="margin-left:75px;margin-top:10px;">
                        <input type="image" src="img/publishsurvey.png"/>
                    </div>
                </div>

                <div id="rightcontent" style="width:640px;float:left;margin-top:5px;">
                    <div id="questions" style="font-family:myriad-pro-condensed,sans-serif;margin-bottom:10px;">
                    <!--This will hold the question -->
                    </div>
                    <p><button id="addQuestion" style="background:url('img/addquestion.png');border:0;height:28px;width:140px;float:right;"></button></p>
                    <div id="masterQuestion">
                        <!-- This is the hidden master content used for cloning -->
                        <div class="questionChanger" style="float:right;">
                            <select name="question[*][type]" class="dynamic" style="color: #808080;font-family: myriad-pro-condensed,sans-serif;font-size:14px;width:150px;padding:5px;">
                                <option value="type1">Free Text</option>
                                <option value="type2">Multiple Choice</option>
                                <option value="type3">Yes or No</option>
                            </select>
                        </div>

                        <div id="type1" class="questionSet">
                            <h9>Question</h9><br>
                            <div id="articlesep" style="margin-top:15px;margin-bottom:10px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <input type="text" class="dynamic" name="question[*][question]" placeholder="QUESTION" style="padding:2px 2px 2px 15px;width:600px;" />
                            <div id="articlesep" style="margin-bottom:15px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <div id="mediaupload">
                                <div id="uploadbtn" style="float:left;">
                                    <img src="img/uploadimg.png"/>
                                </div>
                                <div id="ortxt" style="float:left;margin-top:45px;margin-left:30px;">
                                    <h9>OR</h9> <input type="text" placeholder="LINK TO URL OF IMAGE OR VIDEO" class="dynamic" name="question[*][medialink]" style="padding:2px 2px 2px 15px;width:315px;margin-left:30px;"/>
                                </div>
                                <div id="clearfix"></div>
                            </div>
                            <label for="file">Filename:</label>
                            <input type="file" name="file" id="file"><br>
                        </div>

                        <div id="type2" class="questionSet">
                            <h9>Question</h9><br>
                            <div id="articlesep" style="margin-top:15px;margin-bottom:10px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <input type="text" class="dynamic" name="question[*][question]" placeholder="QUESTION" style="padding:2px 2px 2px 15px;width:600px;" />
                            <div id="articlesep" style="margin-bottom:15px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <div id="mediaupload">
                                <div id="uploadbtn" style="float:left;">
                                    <img src="img/uploadimg.png"/>
                                </div>
                                <div id="ortxt" style="float:left;margin-top:45px;margin-left:30px;">
                                    <h9>OR</h9> <input type="text" class="dynamic" placeholder="LINK TO URL OF IMAGE OR VIDEO" name="question[*][medialink]" style="padding:2px 2px 2px 15px;width:315px;margin-left:30px;"/>
                                </div>
                                <div id="clearfix"></div>
                            </div>
                            <div id="articlesep" style="margin-bottom:15px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <input type="text" class="dynamic" name="question[*][answer1]" placeholder="ANSWER 1" style="padding:2px 2px 2px 15px;width:600px;" />
                            <input type="text" class="dynamic" name="question[*][answer2]" placeholder="ANSWER 2" style="padding:2px 2px 2px 15px;width:600px;" />
                            <input type="text" class="dynamic" name="question[*][answer3]" placeholder="ANSWER 3" style="padding:2px 2px 2px 15px;width:600px;" />
                            <input type="text" class="dynamic" name="question[*][answer4]" placeholder="ANSWER 4" style="padding:2px 2px 2px 15px;width:600px;" />
                            <input type="text" class="dynamic" name="question[*][answer5]" placeholder="ANSWER 5" style="padding:2px 2px 2px 15px;width:600px;" />
                        </div>

                        <div id="type3" class="questionSet">
                            <h9>Question</h9><br>
                            <div id="articlesep" style="margin-top:15px;margin-bottom:10px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <input type="text" class="dynamic" name="question[*][question]" placeholder="QUESTION" style="padding:2px 2px 2px 15px;width:600px;" />
                            <div id="articlesep" style="margin-bottom:15px;">
                                <img src="img/s1sep.png" style="width:280px;height:1px;width:620px;"/>
                            </div>
                            <div id="mediaupload">
                                <div id="uploadbtn" style="float:left;">
                                    <img src="img/uploadimg.png"/>
                                </div>
                                <div id="ortxt" style="float:left;margin-top:45px;margin-left:30px;">
                                    <h9>OR</h9> <input type="text" class="dynamic" placeholder="LINK TO URL OF IMAGE OR VIDEO" name="question[*][medialink]" style="padding:2px 2px 2px 15px;width:315px;margin-left:30px;"/>
                                </div>
                                <div id="clearfix"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <input type="hidden" name="submittype" value="1"/>
            </form>

Open in new window


Submit.php
<?php

define("_VALID_PHP", true);
require_once("../init.php");

if (!$user->logged_in)
    redirect_to("../index.php");

$row = $user->getUserData();
$orgid = $row['org_id'];

include '../db.php';

//Survey Creation
if($_POST['submittype'] == 1)
    {
        $title = $_POST['title'];
        $description = $_POST['description'];
        $points = $_POST['amount'];
        $enddate = $_POST['enddate'];
        $userid = $row['id'];

        //Insert the survey record
        $sql="insert into survey_surveys(title,description,points,date_expires,status)
              values('$title','$description','$points','$enddate',1)";
        $db->query($sql);

        //Get SurveyID on item just inserted
        $surveyid = $db->insert_id;

        //Associate Surveys with the corresponding client
        $sql2="insert into surveyassoc(survey_id, org_id)
               values('$surveyid','$orgid')";
        $db->query($sql2);

        //Insert questions and anwers
        foreach ($_POST['question'] as $qNum => $qInfo):
            if($qNum == '*')
                {
                    '';
                }
                else
                {
                    //Insert Questions
                    $question=$qInfo['question'];
                    $mediatype='';
                    $media='';
                    $questiontype=str_replace('type','',$qInfo['type']);

                    $sql3="insert into survey_questions(status,survey_id,question,media_type,media,response_type)
                           values(1,'$surveyid','$question','$mediatype','$media','$questiontype')";
                    $db->query($sql3);

                    //Get QuestionID on item just inserted
                    $questionid = $db->insert_id;

                    //Insert Answers
                    if($questiontype == 1)
                        {
                            '';
                        }
                    if($questiontype == 2)
                        {
                            $answer1=$qInfo['answer1'];
                            $answer2=$qInfo['answer2'];
                            $answer3=$qInfo['answer3'];
                            $answer4=$qInfo['answer4'];
                            $answer5=$qInfo['answer5'];
                            if(empty($answer1))
                            {
                                '';
                            }
                            else
                            {
                                $sql4="insert into survey_answers(question_id, answer, date_added)
                                       values('$questionid','$answer1',NOW())";
                                $db->query($sql4);
                            }
                            if(empty($answer2))
                            {
                                '';
                            }
                            else
                            {
                                $sql5="insert into survey_answers(question_id, answer, date_added)
                                       values('$questionid','$answer2',NOW())";
                                $db->query($sql5);
                            }
                            if(empty($answer3))
                            {
                                '';
                            }
                            else
                            {
                                $sql6="insert into survey_answers(question_id, answer, date_added)
                                       values('$questionid','$answer3',NOW())";
                                $db->query($sql6);
                            }
                            if(empty($answer4))
                            {
                                '';
                            }
                            else
                            {
                                $sql7="insert into survey_answers(question_id, answer, date_added)
                                       values('$questionid','$answer4',NOW())";
                                $db->query($sql7);
                            }
                            if(empty($answer5))
                            {
                                '';
                            }
                            else
                            {
                                $sql8="insert into survey_answers(question_id, answer, date_added)
                                       values('$questionid','$answer5',NOW())";
                                $db->query($sql8);
                            }
                        }
                    if($questiontype == 3)
                        {
                            $sql9="insert into survey_answers(question_id, answer, date_added)
                                       values('$questionid','Yes',NOW())";
                            $db->query($sql9);

                            $sql10="insert into survey_answers(question_id, answer, date_added)
                                       values('$questionid','No',NOW())";
                            $db->query($sql10);
                        }

                    //echo 'Question Number: ';printf($qNum).'<br>';
                    var_dump($qInfo).'<br><br>';
                    //if(empty($qInfo['answer1']))
                    //{
                    //    echo 'Question Type: '.str_replace('type','',$qInfo['type']).'<br>Question Text: '.$qInfo['question'].'<br><br>';
                    //}
                    //else
                    //{
                    //    echo 'Question Type: '.$qInfo['type'].'<br>Question Text: '.$qInfo['question'].'<br>Answer Text:'.$qInfo['answer1'].'<br>Answer Text:'.$qInfo['answer2'].'<br>Answer Text:'.$qInfo['answer3'].'<br>Answer Text:'.$qInfo['answer4'].'<br>Answer Text:'.$qInfo['answer5'].'<br><br>';
                    //}

                    //move_uploaded_file($_FILES["file"]["tmp_name"],
                    //"upload/" . $_FILES["file"]["name"]);
                    //echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

                    $allowedExts = array("gif", "jpeg", "jpg", "png");
                    $temp = explode(".", $_FILES["file"]["name"]);
                    $extension = end($temp);
                    if ($_FILES["file"]["error"] > 0)
                    {
                        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
                    }
                    else
                    {
                        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
                        echo "Type: " . $_FILES["file"]["type"] . "<br>";
                        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
                        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

                        if (file_exists("upload/" . $_FILES["file"]["name"]))
                        {
                            echo $_FILES["file"]["name"] . " already exists. ";
                        }
                        else
                        {
                            move_uploaded_file($_FILES["file"]["tmp_name"],
                                "upload/" . $_FILES["file"]["name"]);
                            echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
                        }
                    }


                }
        endforeach;

        //Redirect
        //header('Location: view-surveys.php');
    }
?>

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39634395
Wouldn't the "index" start with a doctype declaration and an HTML tag?
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39634450
You'll need to create your FILE input the same as the others, using a name as an array, and adding the dynamic class (drop the ID as well)

<input type="file" name="file[*]" class="dynamic">

Now they'll get cloned properly when you add a new question.

They'll also need handling differently in the back end. In your code above you seem to have an IF statement for handling questions of Type 1, which is where your FILE input is, so you need to add the code in there:

if($questiontype == 1) {
   //handle your uploaded file here
   $fileName = $_FILES['file']['name'][$qNum];
   $fileType = $_FILES['file']['type'][$qNum];
   $fileSize = $_FILES['file']['size'][$qNum];
   $fileTmpName = $_FILES['file']['tmp_name'][$qNum];
}

Open in new window

0
 
LVL 11

Author Comment

by:N R
ID: 39634611
Again, works great thanks!

Why is $qNum on the end of the array like that?  Just wondering so I can understand how it works.
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39634694
So that you know which file belongs to which question. You use the $qNum variable because of this line:

foreach ($_POST['question'] as $qNum => $qInfo):

So for each question, $qNum will be set to the queston number. Now, if you have 10 questions, and questions 1,4 and 5 have file uploads, then the information will be stored like this:

$_FILES['file']['name'][1]
$_FILES['file']['name'][4]
$_FILES['file']['name'][5]

which in the foreach loop, becomes

$_FILES['file']['name'][$qNum]

:)
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 39634773
With multi-file uploads the client can omit files.  The $_FILES['error'] will contain "4" in that case.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question