• While attempting to upload via media uploader an .xml file, I get a security error that says it can’t upload .xml file for security reason. How could I bypass this problem?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator James Huff

    (@macmanx)

    What is the URL of your blog, and where/how/why are you trying to upload an XML file?

    Thread Starter Tom1884

    (@tom1884)

    I’m uploading it because I have to share it, downloadable from my site.
    I’m trying to uploading it by media uploader. So it’d will be on uploads/ dir.

    Moderator James Huff

    (@macmanx)

    Ah, ok. The Media uploader only uploads certain files: http://codex.wordpress.org/Uploading_Files#About_Uploading_Files_with_WordPress

    The easiest way around that is to of course upload the file via SFTP or FTP instead: http://codex.wordpress.org/FTP_Clients

    Another way around it is to add this to your theme functions file, which apparently does work, but I honestly never recommend things like this (when FTP is perfectly doable option):

    add_filter('upload_mimes', 'custom_upload_xml');
    
    function custom_upload_xml($mimes) {
        $mimes = array_merge($mimes, array('xml' => 'application/xml'));
        return $mimes;
    }

    via http://ernieleseberg.com/xml-uploads-in-wordpress/

    I have code that does a similar thing as James posted recently.

    Here’s how you can add any file type that can be uploaded as I have used some sample code including a line for xml files. This can be also useful for clients who want to upload files on the site if that is ever an option.

    add_filter('upload_mimes', 'custom_upload_mimes');
    function custom_upload_mimes ( $existing_mimes=array() ) {
    
    	// add your ext => mime to the array
    	$existing_mimes['tif'] = 'image/tif';
    
     	$existing_mimes['eps'] = 'image/eps';
    
     	$existing_mimes['zip'] = 'application/zip';
    
     	$existing_mimes['rar'] = 'application/x-rar-compressed';
    
            $existing_mimes['xml'] = 'application/xml';
    	// add as many as you like
    
    	// and return the new full result
    	return $existing_mimes;
    
    }
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Can't upload an .xml file: security error’ is closed to new replies.