• Hi. I can upload .doc files (and jpgs, pdf’s, etc). But I cannot upload .docx files. I get an “upload failed. Unknown error” message.
    I read somewhere else on this forum that this code added to functions.php could help but it did not work for me:

    if ( isset($GLOBALS[“WFU_GLOBALS”][“WFU_WILDCARD_ASTERISK_MODE”]) ) $GLOBALS[“WFU_GLOBALS”][“WFU_WILDCARD_ASTERISK_MODE”][3] = “loose”;

    Thanks.

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 31 total)
  • Plugin Author nickboss

    (@nickboss)

    Hi, I do not see the upload form if I open the page. Is it hidden for guests?

    Nickolas

    Thread Starter bradwallace51

    (@bradwallace51)

    sorry about that. i enabled it in the sidebar now. thanks so much.

    Thread Starter bradwallace51

    (@bradwallace51)

    hi. any luck on troubleshooting this problem? my client needs .docx uploads to function. thank you!

    Plugin Author nickboss

    (@nickboss)

    I get a 503 error when trying to upload docx files. Maybe they are rejected by the web server. What is your host?

    Nickolas

    Thread Starter bradwallace51

    (@bradwallace51)

    hi. it is a godaddy account (Economy Web Hosting Linux). Thanks

    Thread Starter bradwallace51

    (@bradwallace51)

    i’m not sure if this means anything, but i was able to upload a .docx file to /wp-content/ using godaddy’s file manager without any problem.

    Plugin Author nickboss

    (@nickboss)

    Can you ask Godaddy if they allow docx files? I read in forums that they don’t.

    Nickolas

    Thread Starter bradwallace51

    (@bradwallace51)

    not looking good! i contacted godaddy and they tried to tell me wordpress isn’t compatible with .docx files. then after i showed that i can upload .docx directly to the media library with no problem they said maybe my 3 year old linux server is not compatible with it but can’t verify anything.
    they also upgraded my php from 5.4 to 5.6 but that didn’t help.

    any more ideas? thank you very much.

    Thread Starter bradwallace51

    (@bradwallace51)

    i have access to another modern c-panel godaddy account. i tested an upload form on that site and found it does indeed work for docx files. so maybe the problem actually is their older servers being incompatible with docx. does that seem possible? thank you.

    Plugin Author nickboss

    (@nickboss)

    what happens if you try to upload a docx file that you have renamed to filename.docx000 and you have allowed docx000 extensions to be uploaded?

    Nickolas

    Thread Starter bradwallace51

    (@bradwallace51)

    i tried renaming it .docx000 and even renamed it .doc and it would not upload.
    although a real .doc file will upload. interesting

    Plugin Author nickboss

    (@nickboss)

    Yes indeed, it seems that the web server performs check of the file contents to determine the type of the file. Through this check it thinks that the file is dangerous and rejects it.

    I am working on a more hardcore solution, by zipping the file before upload and then unzipping it. I will get back to you in some hours.

    Nickolas

    Plugin Author nickboss

    (@nickboss)

    Hi, I have prepared a plugin hook that overcomes the problem by zipping the docx file at your browser and unzipping it when uploaded. Here is the code:

    if (!function_exists('wfu_file_upload_output_handler')) {
    	function wfu_file_upload_output_handler($output) {
    		$output .= "
    <script type='text/javascript'>
    var load_JSZip = function() {
    	var head = document.getElementsByTagName('head')[0];
    	var theScript = document.createElement('script');
    	theScript.type = 'text/javascript';
    	theScript.src = 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.4/jszip.min.js';
    	head.appendChild(theScript);
    }();
    if (!window['wfu_selectbutton_changed_orig']) {
    	window['wfu_selectbutton_changed_orig'] = wfu_selectbutton_changed;
    	wfu_selectbutton_changed = function(sid, usefilearray) {
    		wfu_selectbutton_changed_orig(sid, 1);
    		if (typeof GlobalData.WFU[sid].filearrayprops == 'undefined')
    			GlobalData.WFU[sid].filearrayprops = Array();
    	}
    }
    if (!window['wfu_HTML5UploadFile_cont_orig']) {
    	window['wfu_HTML5UploadFile_cont_orig'] = wfu_HTML5UploadFile_cont;
    	wfu_HTML5UploadFile_cont = function(sid, unique_upload_id) {
    		wfu_continue_processing_files(sid, unique_upload_id, 0);
    	}
    }
    function wfu_continue_processing_files(sid, unique_upload_id, start) {
    	var farr = wfu_get_filelist(sid);
    	var i = start;
    	var process_id = -1;
    	while (i < farr.length) {
    		var ext = farr[i].name.replace(/^.*?(\.([^.]*))?$/, '$2').toLowerCase();
    		if (ext == 'docx') {
    			process_id = i;
    			break;
    		}
    		i++;
    	}
    	if (process_id == -1) window['wfu_HTML5UploadFile_cont_orig'](sid, unique_upload_id);
    	else {
    		var zip = new JSZip();
    		zip.file(farr[process_id].name, farr[process_id]);
    		zip.generateAsync({type: 'blob', compression: 'DEFLATE', compressionOptions: {level: 9}}).then(function (docxfile) {
    			GlobalData.WFU[sid].filearray[process_id] = new File([docxfile], farr[process_id].name);
    			wfu_continue_processing_files(sid, unique_upload_id, process_id + 1);
    		}, function error(e) {
    			console.log('error');
    		});
    	}
    }
    </script>
    	";
    		return $output;
    	}
    	add_filter('_wfu_file_upload_output', 'wfu_file_upload_output_handler', 10, 1);
    }
    if (!function_exists('wfu_after_file_loaded_handler')) {
    	function wfu_after_file_loaded_handler($changable_data, $additional_data) {
    		$file = $additional_data["file_path"];
    		$name = wfu_basename($file);
    		$ext = wfu_fileext($name);
    		if ( strtolower($ext) == "docx" ) {
    			$zip = new ZipArchive;
    			$contents = "";
    			if ($zip->open($file) === true) {
    				$contents = $zip->getFromName($name);
    				$zip->close();
    			}
    			$ret = false;
    			if ( $contents != "" )  $ret = file_put_contents($file, $contents);
    			if ( $ret === false ) {
    				$changable_data["error_message"] = "upload failed!";
    			}
    		}
    
    		return $changable_data;
    	}
    	add_filter('wfu_after_file_loaded', 'wfu_after_file_loaded_handler', 10, 2); 
    }

    You have the Free version, so you need to put this code at the end of your functions.php file of your theme. Before you do it, make a backup of functions.php, so that you can roll-over changes if something happens.

    Let me know if it works. I tested it in my environment and it works.

    Nickolas

    • This reply was modified 6 years, 5 months ago by nickboss.
    Thread Starter bradwallace51

    (@bradwallace51)

    Thank you for your hard work. This did not work for me. I’m guessing I cannot upload zip files at all. With or without your code added to the functions.php file, I can’t upload a .docx or .zip file at all. (I tried zipping a standard txt file as my test zip file.) Thanks again for trying all this. I’m hoping you still have more ideas! I may be able to update the website to a newer server if we can’t get this working. But I’m hoping we don’t have to do that.

    Plugin Author nickboss

    (@nickboss)

    Maybe your web server does not support ZipArchive library. Do you have access to the error log of your web server? Maybe we can find what is the error.

    Nickolas

Viewing 15 replies - 1 through 15 (of 31 total)
  • The topic ‘Unable to upload DOCX files’ is closed to new replies.