fatkatie Posted April 12, 2018 Share Posted April 12, 2018 While I can post large files, I cannot post form "data" larger than 1MB. On the submit event I collect the form's textarea data. What I'd like to do is somehow place that data into a form file and post that instead. Can it be done? When I say "form file" I'm talking about the client posted data, saved server side, in the $_FILES[] array. I'm partial to jQuery so feel free to use that package in any example. No, this isn't a school assignment. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/307112-post-form-data-textarea-as-file/ Share on other sites More sharing options...
requinix Posted April 13, 2018 Share Posted April 13, 2018 Have you verified that you can even upload files that large? Quote Link to comment https://forums.phpfreaks.com/topic/307112-post-form-data-textarea-as-file/#findComment-1557806 Share on other sites More sharing options...
fatkatie Posted April 13, 2018 Author Share Posted April 13, 2018 (edited) https://forums.phpfreaks.com/topic/307038-split-form-textarea-data-for-multiple-posts/ I can upload HUGE form 'file' types. The post fails when 'other' types reach exactly 1MB. I serialize the form data and watch the length. I really don't want to go the split data route. Edited April 13, 2018 by fatkatie Quote Link to comment https://forums.phpfreaks.com/topic/307112-post-form-data-textarea-as-file/#findComment-1557821 Share on other sites More sharing options...
requinix Posted April 13, 2018 Share Posted April 13, 2018 Have you tried just switching the form to method="multipart/form-data"in case that's all you need to bypass the restriction? Quote Link to comment https://forums.phpfreaks.com/topic/307112-post-form-data-textarea-as-file/#findComment-1557825 Share on other sites More sharing options...
fatkatie Posted April 13, 2018 Author Share Posted April 13, 2018 Originally I failed to define the enctype, but per the other post's suggestion I included it. Still failed. Here's the code. (I thought multipart is the default. Is that correct?) <form id='idf_big' method="post" enctype="multipart/form-data"> <textarea name="nta_big" id="idta_big" rows="10" cols="80"> This is my textarea </textarea> <input type='submit' id='ids_big' value='Go'> </form> <script> jQuery(document).ready(function() { $( "#idf_big" ).submit(function( event ) { event.preventDefault(); var str = jQuery('#idf_big').serialize(); var sos = str.length; alert("length of serialized data is: " + sos); var ph = jQuery.post('ajax_big_save.php', str); ... Quote Link to comment https://forums.phpfreaks.com/topic/307112-post-form-data-textarea-as-file/#findComment-1557826 Share on other sites More sharing options...
Solution requinix Posted April 13, 2018 Solution Share Posted April 13, 2018 The default is actually application/x-www-form-urlencoded. That's the normal key=value&key=value&... syntax you should recognize. multipart/form-data, mostly used for file uploads, is a far less compact format but better suited for lots of content. Doing this as a fake file upload really sucks. Use the Blob and FormData classes. var fd = new FormData(); var blob = new Blob([/* textarea contents */], { type: "text/plain" }); fd.append("nta_big", blob); var xhr = new XMLHttpRequest(); xhr.open("POST", /* url */, true); xhr.send(fd);Untested but should be close. With jQuery you might be able to use a Blob with its AJAX methods, as in { "nta_big": blob }as part of the sent data. Quote Link to comment https://forums.phpfreaks.com/topic/307112-post-form-data-textarea-as-file/#findComment-1557829 Share on other sites More sharing options...
fatkatie Posted April 13, 2018 Author Share Posted April 13, 2018 YES! It's so simple.... "I thought you'd say that Dr. Watson" var big = jQuery('#idta_big').val(); var blob = new Blob ([big], { type: "text/plain" }); var fd = new FormData(); fd.append("bigstuff", blob); jQuery.ajax({ url : 'ajax_big_save.php.php', method : 'POST', data : fd }); THANK YOU! (Stuff was in the $_FILES array.) Quote Link to comment https://forums.phpfreaks.com/topic/307112-post-form-data-textarea-as-file/#findComment-1557837 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.