0

I am adding an upload function to the HTML div, but for some reason it is not working. I have also created a php file with the same scripts I have added to the div and did the action="upload-page.php", but it does not get the php page either. What could be the problem? Here is the code:

<div class="wall-ptype-cnt wall_text" >
__post_wall_text__
<form method="post" action="upload-page.php" enctype="multipart/form-data">
        <input name="filesToUpload[]" id="filesToUpload" type="file" multiple="" />
<script language="javascript" type="text/javascript">
    var input = document.getElementById('filesToUpload');
    var list = document.getElementById('fileList');


    while (list.hasChildNodes()) {
    list.removeChild(ul.firstChild);
    }


    for (var x = 0; x < input.files.length; x++) {

        var li = document.createElement('li');
        li.innerHTML = 'File ' + (x + 1) + ':  ' + input.files[x].name;
        list.append(li);
    }           
</script>
<?php if(count($_FILES['uploads']['filesToUpload'])) {
foreach ($_FILES['uploads']['filesToUpload'] as $file) {

    //do your upload stuff here
    echo $file;

        }
    }
?>
</form>
</div>

Why does the php page is not being processed and why the script is not working as well? The script I have in upload-page.php is the same I am putting inside html.

4
  • I haven't really read this through but first of all your javascript should be contained in a window.onload = function() { Commented Mar 20, 2013 at 13:27
  • You need to tell it where to upload your files in the section marked //do your upload stuff here. There is nothing showing where your files are uploaded to, unless you're not showing us your entire code. Consult the PHP manual: php.net/manual/en/features.file-upload.php Commented Mar 20, 2013 at 13:27
  • you don't have any "fileList" id element in the page so you might get js error Commented Mar 20, 2013 at 13:29
  • I included my js inside window.onload function() {},still not working the way it should. It is the full code. Before I tried to add uploadify or uploadifive inside my html div, and it was not working for me either.. Commented Mar 20, 2013 at 13:33

1 Answer 1

1

A couple of mistakes in your code:

  1. "list.removeChild(ul.firstChild);" should be "list.removeChild(list.firstChild);"
  2. "list.append(li);" should be "list.appendChild(li);"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.