upperbid Posted September 11, 2011 Share Posted September 11, 2011 I'm good at PHP but don't know much about JavaScript. I am stuck on this job because I cannot figure out how to pass the file name(s) (there can be more than one) from the one page to the next or even how to print the file name(s) cause the code for uploading the file to the server is all in JavaScript. I need to be able to identify the file names somehow, and then to pass them using PHP. I have already passed everything else on the page, I just can't get this. Any help would be appreciated. Here is the code for the function: function add_file(file) { var j = i - 1; var box = document.getElementById('file_list'); var num = box.length; var file_exists = 0; if (file_exists == 0) { // For Internet Explorer try { el = document.createElement('<input type="file" name="userfile[]" id="file_' + i + '" size="30" onChange="javascript:add_file(this.value);">'); } // For other browsers catch (e) { el = document.createElement('input'); el.setAttribute('type', 'file'); el.setAttribute('name', 'userfile[]'); el.setAttribute('id', 'file_' + i); el.setAttribute('size', '12'); el.setAttribute('onChange', 'javascript:add_file(this.value);'); } if(i==0){ document.getElementById('frontfiles').innerHTML='No file Selected'; } else { document.getElementById('frontfiles').innerHTML=i+' files Selected'; } document.getElementById('file_' + j).style.display document.getElementById('file_' + j).style.display = 'none'; if (document.getElementById('list_div').style.display == 'none') { document.getElementById('list_div').style.display = 'block'; } document.getElementById('files_div').appendChild(el); box.options[num] = new Option(file, 'file_' + j); i++; } } And here is the form part: </div> </div> <div class="Printing3_Box1"> <!--printContact--> <div class="uploadtxtCover"> <!--uploadtxt--> <div style="float:left; width:239px;"> <div class="chosefiles"> <!-- <img src="images/chosefile.jpg" alt="Chose file" /><br />--> <span class="chooseend"> Files to upload (FRONT) : <span id="frontfiles">No file selected</span></span><br /> </div> <div class="chosefiles"> <div name="files_div" id="files_div" style="float:left;"> <input type="file" name="userfile[]" id="file_0" size="12" onChange="javascript:add_file(this.value);"> </div> </div> <div class="chosefiles"> <div name="list_div" id="list_div" style="display: none;"> <select multiple name="file_list" id="file_list" size="8" style="width:190px; height:22px;"></select> <br> <input type="button" id="remove_file_btn" value="Remove Selected" onClick="javascript:remove_file();"> </div> </div> Please keep this simple if you can help. I need to get names like this: [folder]/[file name].[ext] e.g. files/108078.jpg If someone can tell me how to make the variable in PHP from the above code, I can probably easily pass the data along with the rest of the data I already got working. Thanks for any help Robert Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 12, 2011 Share Posted September 12, 2011 It appears that you are doing all you need to do already. You have js building a set of html input fields with an array name field. Submit the form and have your php retrieve your array elements and that's it. Or am I missing something here? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.