njdubois Posted March 25, 2013 Share Posted March 25, 2013 I am trying to upload a single file, and from this page https://developer.mozilla.org/en-US/docs/Using_files_from_web_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.marcomtechnologies.com/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 Link to comment https://forums.phpfreaks.com/topic/276153-upload-audio-questionsingle-file-ie-issue/ Share on other sites More sharing options...
njdubois Posted March 26, 2013 Author Share Posted March 26, 2013 *bump bump* Anyone know a way to solve this problem? Thanks Nick Link to comment https://forums.phpfreaks.com/topic/276153-upload-audio-questionsingle-file-ie-issue/#findComment-1421159 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.