0

Hi i am trying to post multiple files by implementing 3 input file html controls but when data is posted only one file[index] is received and others are not received. Here is my Html form

      <form action="" id="form"  method="post" enctype="multipart/form-data">
      <input type="text" id="abtitle" name="abouttitle" placeholder="Title" required />
      <textarea id="msg" name="aboutmessage" placeholder="Message" required></textarea>
          <p><input type="file" name="pic1" id="pic1" /></p>
            <p><input type="file" name="pic2" id="pic2" /></p>
            <p><input type="file" name="pic3" id="pic3" /></p>
              <input type="button" name="contactsubmit" id="contactbtn" value="Submit"/>
    </form>    

   <script src="../../js/jquery-1.11.2.min.js"></script>

<script type="text/javascript">
$("#contactbtn").click(function(){
var pic1 = $('#pic1').prop('files')[0];
 var pic2 = $('#pic2').prop('files')[0];
 var pic3 = $('#pic3').prop('files')[0];
 var title=$("#abtitle").val();
    var msg=$("#msg").val();
 var form_data = new FormData();


form_data.append('Title',title);
form_data.append('Msg',msg);                  
form_data.append('file1',pic1);
form_data1.append('file2',pic2);  
form_data.append('file3',pic3);

            $.ajax({
     url: "../../code/aboutuscode.php", 
     type: "POST",             
     data: form_data, 
     contentType: false,       
     cache: false,             
     processData:false,        
     success: function(data) 
     {

      alert(data);
       }
      });

"aboutuscode.php"

     <?php $tmpfile1=$_FILES['file1']['tmp_name'];

$tmpfile2=$_FILES['file2']['tmp_name'];
$tmpfile1.=$tmpfile2;
echo $tmpfile1;
    ?>
Syed Abdullah
  • 25
  • 1
  • 3
  • 7
  • 2
    you're using `pic2`, but are sending `file2`. – Marc B Jun 02 '15 at 14:08
  • @MarcB I have corrected file1 and file2 but it is still not working. I am getting file1 index only not more than one file – Syed Abdullah Jun 02 '15 at 14:15
  • so start debugging: `var_dump($_FILES)` and see what you really received. – Marc B Jun 02 '15 at 14:16
  • Hey @MarcB after dump it is saying array (size=0) empty – Syed Abdullah Jun 02 '15 at 16:01
  • then no files were upload, or you're doing the upload incorrectly. – Marc B Jun 02 '15 at 16:02
  • Hey @MarcB it is working correctly on Fire Fox but not on Chrome On Firefox i received this: array (size=2) 'file1' => array (size=5) 'name' => string '34.jpg' (length=6) 'type' => string 'image/jpeg' (length=10) 'tmp_name' => string 'C:\wamp\tmp\php2919.tmp' (length=23) 'error' => int 0 'size' => int 620888 'file2' => array (size=5) 'name' => string 'Desert.jpg' (length=10) 'type' => string 'image/jpeg' (length=10) 'tmp_name' => string 'C:\wamp\tmp\php2929.tmp' (length=23) 'error' => int 0 'size' => int 84594 – Syed Abdullah Jun 02 '15 at 16:13

0 Answers0