dorisdong0514
2017-04-21 19:57
浏览 67
已采纳

php从一个dir重命名(移动)到另一个两个级别

my script file path is:

C:\xampp\htdocs\wordpress\wp-content\plugins\test\test.php

I need to run code from this path that will move images from path:

C:\xampp\htdocs\wordpress\wp-content\uploads\2017\04

to:

C:\xampp\htdocs\wordpress\wp-content\uploads\images

My problem is that I have no idea how to force "rename" go two directories back in path.

I was trying something like:

$srcPath = realpath(dirname(__FILE__) . '/../..' . '/uploads/2017/04/obrazek.png');

error I'm getting atm (I've changed my folder permissions, so maybe it is something with path?):

Warning: rename(C:\xampp\htdocs\wordpress\wp-content\uploads\2017\04\obrazek.png,C:\xampp\htdocs\wordpress\wp-content\uploads\images): access denied
. (code: 5) in C:\xampp\htdocs\wordpress\wp-content\plugins\uploadsdir-manager\test.php on line 16

edit rename code:

$srcPath = realpath(dirname(__FILE__) . '/../..' . '/uploads/2017/04/obrazek.png');
$destPath = realpath(dirname(__FILE__) . '/../..' . '/uploads/images');
/*$srcDir = opendir($srcPath);*/
echo $srcPath ;

sleep(1); 
rename($srcPath, $destPath);

图片转代码服务由CSDN问答提供 功能建议

我的脚本文件路径为:

C:\ xampp \ htdocs \ wordpress \ wp-content \ plugins \ test \ test.php

我需要从此路径运行代码,以便从路径移动图像:

C:\ XAMPP \ htdocs中\ WordPress的\可湿性粉剂内容\上传\ 2017 \ 04

为:

C:\ XAMPP \ htdocs中\ WordPress的 \ wp-content \ uploads \ images

我的问题是我不知道如何强制“重命名”将两个目录放回路径中。

我尝试的是:

  $ srcPath = realpath(dirname(__ FILE__)。'/。/ ..')。  '/uploads/2017/04/obrazek.png');
nn

error我正在获取atm(我已经更改了我的文件夹权限,所以也许是 带路径的东西?):

 警告:重命名(C:\ xampp \ htdocs \ wordpress \ wp-content \ uploads \ 2017 \ 04 \ obrazek.png,C:\  xampp \ htdocs \ wordpress \ wp-content \ uploads \ images):访问被拒绝
。  (代码:5)在第16行的C:\ xampp \ htdocs \ wordpress \ wp-content \ plugins \ uploadsdir-manager \ test.php 
   
 
 

编辑重命名 代码:

  $ srcPath = realpath(dirname(__ FILE__)。'/。/ ..'。'/ uploads/2017/04 / obrazek.png'); \  n $ destPath = realpath(dirname(__ FILE__)。'/../ ..'。'/ uploads / images'); 
 / * $ srcDir = opendir($ srcPath); * / 
echo $ srcPath; 
  
sleep(1);  
rename($ srcPath,$ destPath); 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题