Unable to check if image uploaded by wp_image_editor exists using file_exists function

Question

I am developing a podcast theme where i have a form that allows the user to upload their podcast cover arts. The Podcast cover art’s dimension should fall under 1400×1400 and 3000×3000 since we are following iTune’s regulations.

Since such big files will impact the page load speed of the site i wanna resize the uploaded image to a smaller size, say 250×250 so that we can use that to display on our web pages.

I have used WP_Image_Editor::resize function to resize the uploaded image and WP_Image_Editor::save function to save it. It actually worked. I now have two different images with two different dimensions.
Since a lot of our user’s have already posted their podcast with the bigger images, i simply cannot exclusively show the compressed version. Instead i wanna check if a compressed version exists or not and show the image accordingly.

I have used PHP’s file_exists function to check for the compressed version of the images. But it seems, it always returns false in the case of compressed images. But i can access it through the browser by typing in the full address.

file_exists('path/to/original_image'); = true
file_exists('path/to/compressed_image'); = false

I have used wp_handle_upload to upload the original image but wp_image_editor class to resize and save the compressed one. So there must be something different with these two functions that’s causing this issue.

I have hosted this on wordpress.org and when i try to access the compressed files (which are inside the upload folder) through FTP i can’t see them, but are accessible through browser.

Do you guys have any idea, how i can get over this ? Any help would be greatly appreciated.

Thanks in advance.

0
, , , Rahul K 6 months 2020-08-27T06:10:23-05:00 0 Answers 43 views 0

Leave an answer