Jump to content


Photo

upload audio question(single file, IE issue)


  • Please log in to reply
1 reply to this topic

#1 njdubois

njdubois

    Advanced Member

  • Members
  • PipPipPip
  • 163 posts

Posted 25 March 2013 - 06:43 PM

I am trying to upload a single file, and from this page https://developer.mo...eb_applications

 

I was able to put together a sample script that works in Chrome and Firefox.  One look at the script, and its clear why it doesn't work in IE.

 

var selected_file = document.getElementById('input').files[0];

 

IE doesn't support uploading multiple files.  My problem is that I search this problem on the net and I find questions pertaining to uploading multiple files, and the replies go all over the place and they are all talking about uploading many files.  I just want to upload one file.  Is there something I can do to that one line, that would make the below scripts work in Chrome, FF and IE?

 

I was thinking something like

 

var selected_file = document.getElementById('input').file;

 

Of course that doesn't work.

 

The main page script:

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript">

        function sendFile(file) {
            var uri = "/test_ajax_upload.php";
            var xhr = new XMLHttpRequest();
            var fd = new FormData();
             
            xhr.open("POST", uri, true);
            xhr.onreadystatechange = function() {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    // Handle response.
                    alert(xhr.responseText); // handle response.
                }
            };
            fd.append('myFile', file);
            // Initiate a multipart/form-data upload
            xhr.send(fd);
        }
 
	function start_upload_stuff() {
		var selected_file = document.getElementById('input').files[0];
		sendFile(selected_file);
	}
</script>
</head>
<body>
<input type="file" id="input" name="input">
<br />
<input type="button" id="start_upload" name="start_upload" Value="Start Upload" onclick="start_upload_stuff();" />

</body>
</html>

 

And test_ajax_upload.php:

<?php
if (isset($_FILES['myFile'])) {
    // Example:
    move_uploaded_file($_FILES['myFile']['tmp_name'], "uploads/" . $_FILES['myFile']['name']);
    exit;
}
?>

 

 

 

You can see this code live at http://www.marcomtec...test_upload.php

 

Any assistance is greatly appreciated!  What I really like about the above script is it is not using any additional plug ins, its clean and just does what I need it to do, minus not working in IE of course!

 

Thanks!!!

Nick



#2 njdubois

njdubois

    Advanced Member

  • Members
  • PipPipPip
  • 163 posts

Posted 26 March 2013 - 10:44 AM

*bump bump*

 

Anyone know a way to solve this problem?

 

Thanks

 

Nick






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com