• Hi!
    Trying to allow upload of gpx files.

    Have search the internet for solutions and tried both:

    function my_myme_types($mime_types){
    $mime_types['gpx'] = 'application/gpx+xml'; 
    return $mime_types;
    }
    add_filter('upload_mimes', 'my_myme_types', 1, 1);
    
    function my_myme_types($mime_types){
    $mime_types['gpx'] = 'gpx=application/gpx+xml'; 
    return $mime_types;
    }
    add_filter('upload_mimes', 'my_myme_types', 1, 1);

    But when I try to upload a gpx-file I get the error: “Sorry, this file type is not permitted for security reasons.”

    How do i solve this?

    • This topic was modified 5 years, 1 month ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Use 'text/xml' for the MIME type. It’s not quite correct for .gpx files, but it makes the file security checker happy. It doesn’t like very many of the “application/*” types. “text/xml” is not actually incorrect, after all .gpx truly is a XML data file.

    Thread Starter linusbjork

    (@linusbjork)

    Hi! I think you’re right when you say it should be text/xml but it still doesn’t work ??
    When I try to fetch the mime type from the gpx file I get the result “text/xml”.

    echo mime_content_type($filename)
    > text/xml

    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    foreach (glob("*") as $filename) {
        echo finfo_file($finfo, $filename) . "\n";
    }
    finfo_close($finfo);

    > directory
    > text/html
    > text/xml

    the test gpx file looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <gpx version="1.1" creator="Movescount - https://www.movescount.com" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.topografix.com/GPX/1/1 https://www.topografix.com/GPX/1/1/gpx.xsd https://www.cluetrust.com/XML/GPXDATA/1/0 https://www.cluetrust.com/Schemas/gpxdata10.xsd https://www.garmin.com/xmlschemas/TrackPointExtension/v1 https://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd" xmlns:gpxdata="https://www.cluetrust.com/XML/GPXDATA/1/0" xmlns:gpxtpx="https://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns="https://www.topografix.com/GPX/1/1">
       <rte>
          <name>FJM Salomon 27K</name>
          <rtept lat="63.215577" lon="13.055972">
             <ele>550</ele>
          </rtept>
          <rtept lat="63.215597" lon="13.055838">
             <ele>550</ele>
          </rtept>
          <rtept lat="63.215621" lon="13.055691">
             <ele>550</ele>
          </rtept>
          <rtept lat="63.259668" lon="13.186767">
             <ele>668</ele>
          </rtept>
       </rte>
    </gpx>
    • This reply was modified 5 years, 1 month ago by linusbjork.

    I’m also having this problem.

    Several people have written that the solution is to download a plugin called

    “WP Add Mime Types”

    Here’s a description of what someeone wrote worked.

    https://www.ads-software.com/support/topic/sorry-this-file-type-is-not-permitted-for-security-reasons-15/

    Sadly, it has yet to work for me.

    Still trying to figure out what these people did correctly that I didn’t.

    Hope we can move this discussion along.

    Nothing worked for me with gpx files until I saw that the Mac identifies a gpx file as gpsxml So in functions.php I added the mime types –

    $mimes['gpx'] = 'text/gpsxml'; 
    $mimes['gpx'] = 'application/gpsxml';

    And now I can upload a gpx file.

    Full code (lots of duplication to try and cover every eventuality):

    function custom_mime_types( $mimes ) { 
    // Add new MIME types here
    $mimes['kml'] = 'application/vnd.google-earth.kml+xml';
    $mimes['gpx'] = 'application/gpx+xml';
    $mimes['gpx'] = 'application/xml';
    $mimes['gpx'] = 'text/xml';
    $mimes['gpx'] = 'text/gpx';
    $mimes['gpx'] = 'text/gpsxml';
    $mimes['gpx'] = 'application/gpsxml';
    
    return $mimes;
    }
    add_filter( 'upload_mimes', 'custom_mime_types' );
    • This reply was modified 4 years, 5 months ago by digbymaass.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘allow gpx-file upload fails’ is closed to new replies.