Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"An error occurred in the upload. Please try again later" in wordpress when uploading images to editor

Tags:

wordpress

I finally found the solution to this problem which as turns out plagues many wordpress installations. Right after uploading an image through the "add media" button in an editor, the upload would fail with a "an error occurred in the upload error". However after refreshing the image would appear in the media browser window but when inserted into the editor it would show up with width and height both set to 1px.

After searching a lot without any success I solved the problem. Many people reported solving it by disabling all plugins one by one to find which was causing the problem. In my case it was a fresh wordpress installation without anything else, not even custom themes. So I decided to post it here in case anyone else is search and stumbles upon this post.

like image 876
John Avatar asked Feb 12 '14 11:02

John


People also ask

Why is WordPress not allowing me to upload images?

The image upload issue in WordPress is typically caused by incorrect file permissions. Your WordPress files are stored on your web hosting server and need specific file and directory permissions to work. Wrong file permissions prevent WordPress from reading or uploading file on the hosting server.


2 Answers

As Indicated by Andrei G, the issue is indeed linked to an auto_increment issue on the database.

Here's what fixed it for me:

DELETE FROM wp_termmeta  WHERE meta_id=0;
DELETE FROM wp_terms  WHERE term_id=0;
DELETE FROM wp_term_taxonomy  WHERE term_taxonomy_id=0;
DELETE FROM wp_commentmeta  WHERE meta_id=0;
DELETE FROM wp_comments  WHERE comment_ID=0;
DELETE FROM wp_links  WHERE link_id=0;
DELETE FROM wp_options  WHERE option_id=0;
DELETE FROM wp_postmeta  WHERE meta_id=0;
DELETE FROM wp_users  WHERE ID=0;
DELETE FROM wp_posts  WHERE ID=0;
DELETE FROM wp_usermeta  WHERE umeta_id=0;

ALTER TABLE  wp_termmeta ADD PRIMARY KEY(meta_id);
ALTER TABLE  wp_terms ADD PRIMARY KEY(term_id);
ALTER TABLE  wp_term_taxonomy ADD PRIMARY KEY(term_taxonomy_id);
ALTER TABLE  wp_commentmeta ADD PRIMARY KEY(meta_id);
ALTER TABLE  wp_comments ADD PRIMARY KEY(comment_ID);
ALTER TABLE  wp_links ADD PRIMARY KEY(link_id);
ALTER TABLE  wp_options ADD PRIMARY KEY(option_id);
ALTER TABLE  wp_postmeta ADD PRIMARY KEY(meta_id);
ALTER TABLE  wp_users ADD PRIMARY KEY(ID);
ALTER TABLE  wp_posts ADD PRIMARY KEY(ID);
ALTER TABLE  wp_usermeta ADD PRIMARY KEY(umeta_id);

ALTER TABLE wp_termmeta CHANGE meta_id meta_id  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE wp_terms CHANGE term_id term_id  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE wp_term_taxonomy CHANGE term_taxonomy_id term_taxonomy_id  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE wp_commentmeta CHANGE meta_id meta_id  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE wp_comments CHANGE comment_ID comment_ID  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE wp_links CHANGE link_id link_id  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE wp_options CHANGE option_id option_id  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE wp_postmeta CHANGE meta_id meta_id  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE wp_users CHANGE ID ID  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE wp_posts CHANGE ID ID  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE wp_usermeta CHANGE umeta_id umeta_id  BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT;

As taken from here

like image 151
trolologuy Avatar answered Oct 06 '22 18:10

trolologuy


Sometimes this problem comes with uploading/restoring the db-backup from file via phpmyadmin. The import can skip adding auto_increment to wp_posts and wp_postmeta tables at 0 key.

This leads to crash in the further work of the site and eventually you wan't be able to add new posts/pages ("you are currently editing the page that shows your latest posts" instead of the text editor), upload new images (you'll see the empty window where once was all your image gallery).

The issue can be easily fixed by deselecting the checkbox near the "Do not use AUTO_INCREMENT for zero values" when importing DB through import section of phpmyadmin. However, it still can be imported with errors and you'll need to add auto_increment to wp_posts and wp_postmeta tables manually after the import complete.

screenshot

like image 23
Andrei G. Avatar answered Oct 06 '22 19:10

Andrei G.