英文:
How do I rename a php image that has a period (.) in the name
问题
我正在尝试使用PHP的rename()
函数来重命名一个文件名中带有句点的图像。
rename("images/cat.cute.jpg", "images/cute-cat.jpg");
目前出现了"找不到文件或目录"错误。
英文:
Im trying to rename an image that has a full stop in the name with php using the rename()
function.
rename("images/cat.cute.jpg", "images/cute-cat.jpg");
Currently getting a "No such file or directory" error.
答案1
得分: 1
当你指定images/cat.cute.jpg
时,你实际上是在指定一个相对于你的PHP脚本执行位置的路径。你收到的错误只是在告诉你,在与脚本执行位置相对的images
文件夹中没有名为cat.cute.jpg
的文件,或者根本不存在这样一个images
文件夹。要解决这个问题,你需要指定正确的相对路径,或者你可以指定一个绝对路径。以下是一个使用绝对路径的rename()
的示例:
rename("/images/cat.cute.jpg", "/images/cute-cat.jpg");
这假设相对于根目录存在一个images/
文件夹,但这可能并非实际情况,你可以根据需要进行调整。
英文:
When you specify images/cat.cute.jpg
, you are specifying a path relative to wherever your PHP script is actually executing. The error you are getting is simply telling you that there is no file called cat.cute.jpg
in the folder images
relative to the execution location of the script. Or, such a folder images
does not exist. To fix this, you either need to specify the correct relative path, or you may specify an absolute path. Here is an example of using rename()
with absolute paths:
rename("/images/cat.cute.jpg", "/images/cute-cat.jpg");
This assumes that there is an images/
folder relative to root, which may not be the case, but you can adjust as you need.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论