Title: PHP Warning when uploading via WP API
Last modified: June 25, 2020

---

# PHP Warning when uploading via WP API

 *  [David](https://wordpress.org/support/users/davidfuhr/)
 * (@davidfuhr)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/php-warning-when-uploading-via-wp-api/)
 * When uploading Media files (in my case PDF, PNG, HTM and JPG) via the WP REST-
   API I got a PHP Warning “Undefined Index: file in resmushit.php:114”. The corresponding
   PHP line is
 * `$basefile = basename($attachments[ 'file' ]);`
 * Turning off auto-optimization resolved the error (as resmushit is not executed
   anymore automatically on upload).

Viewing 1 replies (of 1 total)

 *  Plugin Contributor [reSmush.it](https://wordpress.org/support/users/resmushit/)
 * (@resmushit)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/php-warning-when-uploading-via-wp-api/#post-13147039)
 * Hi [@davidfuhr](https://wordpress.org/support/users/davidfuhr/),
 * Sorry for this late reply.
    Thanks for this interesting feedback. It’s normal
   that this function should be called, but the attachment array you should be empty.
   Can you provide us lines of code you’ve used, to reproduce your problem?
 * Cheers,
    Charles

Viewing 1 replies (of 1 total)

The topic ‘PHP Warning when uploading via WP API’ is closed to new replies.

 * ![](https://ps.w.org/resmushit-image-optimizer/assets/icon-256x256.png?rev=3049668)
 * [reSmush.it : The original free image compressor and optimizer plugin](https://wordpress.org/plugins/resmushit-image-optimizer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/resmushit-image-optimizer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/resmushit-image-optimizer/)
 * [Active Topics](https://wordpress.org/support/plugin/resmushit-image-optimizer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/resmushit-image-optimizer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/resmushit-image-optimizer/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)

 * 1 reply
 * 2 participants
 * Last reply from: [reSmush.it](https://wordpress.org/support/users/resmushit/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/php-warning-when-uploading-via-wp-api/#post-13147039)
 * Status: not resolved