Fabrizio La Racca
Fabrizio La Racca

Reputation: 75

Wordpress on localhost doesn't show pictures loaded via FTP in different directory than uploads

I am migrating 100GB of pictures from an old program to WP in localhost (WAMP 3.0.6). I have uploaded the whole directory in WP within a plugin ('/wp-content/my-plugin/photo_dir/') and I have associated each image to its user using usermeta.

What is weird is that although any pics gives a 404 error (even when I copy-paste its url on the browser), If I load the same picture using media library or my own ajax function (which puts the file in the same directory '/wp-content/my-plugin/photo_dir/') the pic is regularly shown.

My own ajax function uses wp_upload_bits with a redefine UPLOAD_DIR.

// Set custom setup.
                add_filter( 'upload_dir',   'derm_upload_viso_dir' ); // path override.

                    // WordPress will move the file to a differente directory.
                    $upload = wp_upload_bits($fileName, null, file_get_contents($_FILES["myfile"]["tmp_name"]));
                // Set everything back to normal.
                remove_filter( 'upload_dir',    'derm_upload_viso_dir' );

I tried to change permission on the folder (which I can't). I thought I had to 'register' the image as a post but wp_upload_bits doesn't do that and it shows fine after.

Anyone can help?

Upvotes: 1

Views: 297

Answers (1)

Chandra Kumar
Chandra Kumar

Reputation: 4205

It looks like you can define a new upload directory by adding

define('UPLOADS', 'images/uploads');

at the bottom of your wp-config.php file.

Upvotes: 1

Related Questions