This question is related to this other problem i posted some minutes ago: wp_generate_attachment_metadata is creating an empty array

I'm making a new post because the argument is a little different. As said in the other post i have the wp_generate_attachment_metadata function making an empty array, i almost solved the problem by doing a custom array like this:

$new_image_info = getimagesize($new_file_url);
$custom_attach_data = array(
        'width' => $new_image_info[0],
        'height' => $new_image_info[1],
wp_update_attachment_metadata( $attach_id, $custom_attach_data );
set_post_thumbnail( $attach_id, $attach_id );

With this "new" method the image is uploaded correctly and i got thumbnail and image size (width and height), the problem is that i'm missing thefilesize info, and for that i've seen in the doc there is no way to update this information manually with update_attachment_metadata. I tried to put 'size' => filesize($new_file_path) but is not working.

Thank you in advance.

Update: i also noticed that the filesize() function is not working, i get the error:

[24-Sep-2019 14:25:48 UTC] PHP Warning:  filesize(): stat failed for /var/www/html/demosite.com/wp-content/uploads/2019/09/20170610_205517_web_optimized.png in /var/www/html/demosite.com/wp-content/plugins/demo-plugin/demo-main-file.php on line 91

At first i thinked it was a permission problem, but even with everything assignet to www-data:www-data and 775, is still not working. Maybe this can be the real issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.