wordpress复制插件已将文件上传到主题目录


wordpress copy plugin uploaded file to theme dir

我有一行代码,应该将图像从一个目录复制到另一个目录:

copy("http://localhost:8080/wordpress/wp-content/uploads/2015/06/uploaded_background.jpg","http://localhost:8080/wordpress/wp-content/themes/landing-page/img/desktop-background.jpg");

这位于wordpress主题header.php文件中,但我收到一条错误消息:

警告:副本(http://localhost:8080/wordpress/wp-content/themes/landing page/ig/desktop-background.jpg):无法打开流:HTTP包装不支持可写中的连接C: ''wamp''www''wordpress''wp-content''themes''landingpage''header.php on第42行

第42行是我的复制功能行所在的位置。

我该如何解决这个问题。任何建议或链接都会有很大帮助。

而不是使用

 copy("http://localhost:8080/wordpress/wp-content/uploads/2015/06/uploaded_background.jpg","http://localhost:8080/wordpress/wp-content/themes/landing-page/img/desktop-background.jpg");

尝试

copy`("/yourserverfolderpath/wordpress/wp-content/uploads/2015/06/uploaded_background.jpg","/yourserverfolderpath//wordpress/wp-content/themes/landing-page/img/desktop-background.jpg");`

yourserverfolderpath/可能类似于/home/user/abc/

关于的确切路径,请参阅ftp或cpanel

将这个SO问题视为指南

PS:在本地文件的情况下,路径将类似于D:'php'www'www'xml.php

正如@dlegall在评论中指出的那样,根据文档,copy()的第一个参数可以是有效的URL,请参阅此处的文档

由于http协议不支持文件覆盖,因此应该使用本地路径作为copy()的第二个参数。

目标路径。如果dest是URL,则如果包装器不支持覆盖现有文件,则复制操作可能会失败。来源:http://php.net/manual/en/function.copy.php