0

I wrote a function in my functions.php which automatically renames images in the uploads folder of WordPress with [rename()][1].
I tried different solutions but I always get the error

No such file or directory in functions.php

. Paths which I tried, but no success:

../wp-content/uploads/2018/05/image-235.jpg

/../../wp-content/uploads/2018/05/image-235.jpg

/var/www/vhosts/domain.com/dev/home/themename/wp-content/uploads/2018/05/image-235.jpg

/www/vhosts/domain.com/dev/home/themename/wp-content/uploads/2018/05/image-235.jpg

Someone has an idea which could be the right path to rename an image which is in the upload folder? Thank you for your help

EDIT/SOLUTION:

A simple mistake: I have a htaccess with a htpasswd. If I remove the password, file will be found.

  • What's the context here? Keep in mind that media attachments in the database have a reference to the filename that will also need to be updated, not to mention the names of the thumbnail and other sizes of the image would also need to be changed, as well as the database records that refer to them. – Jacob Peattie Sep 1 '18 at 4:01
  • Thanks for your reminding, but my function already updates the paths in the database, which works fine. The Context: I try to rename uploaded images with special characters like ä, ö, ü etc. For that I replace this letters with "normal" ones and after that I want to rename that file. Replacing works fine, but renaming doesn't. It doesn't find such a file or directory even if I use a name with sepcial characters or not. – fabhack Sep 1 '18 at 10:05
  • Find the mistake. Edited my question with the solution – fabhack Sep 1 '18 at 10:38

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.