It looks like the file upload is handled via Ajax, so also check you browser console for possible errors after attempting an upload.
The default file upload handler for WP is wp_media_upload_handler(). Your plugin might use this, or use one of its sub-functions, or manage its own file upload independent of WP functions.
With no hints from error logs, about all you can do is carefully debug the upload handling code. See where the upload request goes by using the network developer tool of your browser. If Ajax is used as part of a WP upload, the POSTed data will include an “action” parameter which is used to create a action tag in the form of "wp_ajax_{$_POST['action']}"
. Examine the global $wp_filter array for the tag resulting from that code. The associated callback function will be the upload handler.
If WP Ajax is not used, the destination of the POST likely contains the upload handler code.
]]>if ( !function_exists( 'wp_handle_upload' ) )
require_once( ABSPATH . 'wp-admin/includes/file.php' );
The code above is the only code I can find that handles the upload. Should it read wp_media_upload_handler please?
Thanks
Rich
]]> public function path_metabox( $path ) {
/** Register all path metaboxes */
add_meta_box( 'im_path_details', __( 'Path Details', self::$TEXTDOMAIN ), array( $this, 'path_metabox_details' ), 'path', 'normal' );
}
public function path_metabox_details( $path ) {
$path = $path->filter( 'raw' );
?>
<table class="form-table">
<tr>
<th>
<label><?php esc_html_e( 'Upload GPX', self::$TEXTDOMAIN ); ?></label>
</th>
<td>
<input type="file" name="path" accept=".gpx"/>
<?php
if ( $path->gpx ) {
?><p><?php
printf( __( 'Current: <a href="%s">%s</a>', self::$TEXTDOMAIN ), esc_attr( $path->gpx ), esc_html( $path->gpx ) );
?></p><?php
}
?>
</td>
</tr>
<tr>
<th>
<label><?php esc_html_e( 'Enter Path Description', self::$TEXTDOMAIN ); ?></label>
</th>
<td>
<?php
wp_editor( $path->description, 'description', array(
) );
?>
</td>
</tr>
</table>
<?php
}
public function maybe_form_uploads( $post ) {
if ( in_array( $post->post_type, array( 'path' ) ) ) {
printf( ' enctype="multipart/form-data"' );
}
}
public function save_path( $path_id, $path, $update ) {
if ( $path->post_type != 'path' )
return;
if ( !empty( $_FILES['path'] ) ) {
$file = $_FILES['path'];
if ( !function_exists( 'wp_handle_upload' ) )
require_once( ABSPATH . 'wp-admin/includes/file.php' );
add_filter( 'mime_types', function( $mimes ) {
return array_merge( $mimes, array(
'gpx' => 'application/gpx+xml'
) );
} );
$file = wp_handle_upload( $file, array( 'action' => 'editpost' ) );
if ( empty( $file['error'] ) )
update_post_meta( $path_id, 'gpx', $file['url'] );
}
if ( isset( $_POST['description'] ) )
update_post_meta( $path_id, 'description', $_POST['description'] );
}
public function add_shortcodes() {
add_shortcode( 'interactivemap', array( $this, 'interactivemap_shortcode' ) );
}
I hope someone can spot the problem.
Thanks
Rich
]]>var_dump $file again after the call and see if any error message is in place.
I’m assuming other WP media uploads work correctly, which rules out any file permissions issues.
Is there an add_filter() call for “upload_mimes” somewhere? I don’t think WP normally allows .gpx uploads. Adding this type to the mimes list through this filter will enable GPX uploads. This filter also passes the current user so only certain users or roles can be allowed to upload GPX files, in case this might be useful to you.
If GPX files are not normally allowed and are not added through the filter, the error returned in $file after calling wp_handle_upload() will say “Sorry, this file type is not permitted for security reasons.”.
]]>I have worked out that the error happened somewhere between:
16th November 2016 – we were able to upload a gpx file
3rd February 2017 – no longer able to upload
During this time WordPress released WordPress 4.7 Vaughan. Did anything significant happen with uploads? Reading the blog release, they did do something with pdf uploads and thumbnails. I can’t work it out.
I have been really ill and not able to do any work until now. Unfortunately, the medicine I am on has scrambled my brain and I am struggling with any sort of coding. I have posted it on jobs.wordpress.net to see if anyone can work out the issue.
If anyone can help I would be so happy.
Thanks
Rich
]]>Sorry to hear you’ve been ill, I know all too well how medication can make coding impossible.
The PDF changes, IIRC, were related to preview images, nothing about the upload process itself.
]]>Rich
]]>I’m assuming other WP media uploads work correctly, which rules out any file permissions issues.
You called it correctly. It is a security issue. It won’t allow files of this type to uploaded.
Rich
]]>I finally got there! WordPress rejected uploading of gpx files via the media area. So I looked at the code and tried a plugin that would allow different uploads. That worked. So worked with another developer this afternoon and he fixed it for me in 10 minutes.
Rich
]]>