I would like to replace one image file with another in PHP. Both have same name (123), but they are in different directory and should have different extension. I want to replace first image with second image.
- ../images/123.gif
- ../images/xxx/123.png
Is it possible with any function? Thank you.
Moving, deleting, copying etc... are all basic actions that are needed whenever working with file systems. As such the documentation will undoubtedly have all of the information you need.
You say that you want to replace the first file with the second.. But you don't mention what you want to happen to the original copy of the second image?
If you rename (i.e. move) it then the file will no longer exist in it's starting location. If you want the file to remain in both directories then you should use
copy
instead.In this case, all you need is:
NOTE: You are able to use relative pats (e.g.
./
and../
)Additional code
Working example