本文介绍了Javascript将$ _FILE ['file']发布到php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 有人可以帮我解决这个问题,我试图改变我的文件上传方案以使用JavaScript,这样我的页面就不会在用户上传文件时提交,谢谢你提前; belove ismy code < script type = text / javascript > 功能fileUplodBtn(fileID){ $('#'+ fileID).trigger('click'); // alert(fileID); } 函数fileUploder(fileID){ //document.getElementById('addrec')。submit(); // var formData = new FormData($(#myForm)。[0]); //$.post('AddFormLogic.php',formData,function(response) var fileInput = document.getElementById(uploadrecipephoto); $ .post( upload.php,{uploadrecipephoto:'uploadrecipephoto'},函数(数据){ alert(data); }); alert(fileInput .files [0] .size); alert(fileInput.value); alert('得到它'); } < / script > < div id = response > < / div > < 输入 type = file id = uploadrecipephoto value = uploadfile 名称 = file style = visibility:hidden / > < tr > < th align = left > < 输入 类型 = 提交 class = btnLogin name =' btnCreateRecipe' value = 创建配方 / > < / th > < th class = file-upload 对齐 = right > < div id =' file_browse_wrapper' type = 提交 onclick = return false onmousedown = javascript:fileUplodBtn('uploadrecipephoto'); > < 输入 type = 隐藏 name = uploadrecipephoto value = recipephoto > < / div > < / th > < / tr > 和我的PHP方面我有捕手 if (isset($ _ FILES [' file'] [' name'])){ getrecphoto( ); $ fileloc = $ _SESSION [' temprecimg']; echo $ fileloc ; echo ' ------ --------'。$ _ SESSION [' ufolder']; echo ' ++++++ +++'。$ _ FILES [' file'] [' type']; echo ' < script type =文本/ JavaScript的>警报( 22222222); < /脚本>'; } 我一直试图解决这个问题3天了!我知道这看起来很愚蠢,但我不知道如何将文件信息发布到php 解决方案 ('#'+ fileID).trigger('click') ; // alert(fileID); } 函数fileUploder(fileID){ //document.getElementById('addrec')。submit(); // var formData = new FormData( (#myForm)。[0]); // .post('AddFormLogic.php',formData,function(response) var fileInput = document.getElementById(uploadrecipephoto ); can someone please help me with this code, Im trying to change my file upload scheme to use JavaScript so that my page doesnt get submitted ever time user uploads a file, THANK YOU IN ADVANCE; belove ismy code<script type="text/javascript"> function fileUplodBtn(fileID) { $('#'+fileID).trigger('click'); //alert(fileID); } function fileUploder(fileID) { //document.getElementById('addrec').submit(); //var formData = new FormData($("#myForm").[0]); //$.post('AddFormLogic.php', formData, function(response) var fileInput = document.getElementById("uploadrecipephoto"); $.post("upload.php",{uploadrecipephoto: 'uploadrecipephoto'}, function(data) { alert(data); }); alert(fileInput.files[0].size); alert(fileInput.value); alert('got it'); }</script> <div id="response"></div><input type="file" id="uploadrecipephoto" value="uploadfile" name="file" style="visibility: hidden" /><tr > <th align="left" > <input type="submit" class="btnLogin" name='btnCreateRecipe' value="Create Recipe" /> </th> <th class="file-upload" align="right"> <div id='file_browse_wrapper' type="submit" onclick="return false" onmousedown="javascript:fileUplodBtn('uploadrecipephoto');" > <input type="hidden" name="uploadrecipephoto" value="recipephoto"> </div> </th></tr>and on my PHP side I have the catcher if (isset($_FILES['file']['name'])){ getrecphoto(); $fileloc= $_SESSION['temprecimg']; echo $fileloc; echo '--------------'.$_SESSION['ufolder']; echo '+++++++++'.$_FILES['file']['type']; echo '<script type="text/javascript"> alert("22222222"); </script>';}I have been trying to figure this out for 3 days now! I know it seems dumb but i just cant figure outhow to post the File info to the php 解决方案 ('#'+fileID).trigger('click'); //alert(fileID); } function fileUploder(fileID) { //document.getElementById('addrec').submit(); //var formData = new FormData(("#myForm").[0]); //.post('AddFormLogic.php', formData, function(response) var fileInput = document.getElementById("uploadrecipephoto"); 这篇关于Javascript将$ _FILE ['file']发布到php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-24 20:32