Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP重命名函数不工作_Php_Rename - Fatal编程技术网

PHP重命名函数不工作

PHP重命名函数不工作,php,rename,Php,Rename,我想使用PHPrename()函数将文件从一个目录移动到另一个目录。但该功能不起作用。每次显示未完成。请提出你的建议 这是我的密码 也许使用完整的本地路径可以做到这一点 $filename = 'images800466507.jpg'; $currentpath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'TempImages' . DIRECTORY_SEPARATOR . $filename; $targetpath = $

我想使用PHP
rename()
函数将文件从一个目录移动到另一个目录。但该功能不起作用。每次显示
未完成
。请提出你的建议

这是我的密码


也许使用完整的本地路径可以做到这一点

$filename = 'images800466507.jpg';

$currentpath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'TempImages' . DIRECTORY_SEPARATOR . $filename;
$targetpath  = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'ImagesNew' . DIRECTORY_SEPARATOR . $filename;

echo realpath( $currentpath ) && rename($currentpath,$targetpath) ? 'done' : 'not done';
源文件是否存在于指定的位置

if( !file_exists( $currentpath ) ) echo 'Bad Foo - ' . $currentpath . ' not found!';

也许使用完整的本地路径可以做到这一点

$filename = 'images800466507.jpg';

$currentpath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'TempImages' . DIRECTORY_SEPARATOR . $filename;
$targetpath  = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'ImagesNew' . DIRECTORY_SEPARATOR . $filename;

echo realpath( $currentpath ) && rename($currentpath,$targetpath) ? 'done' : 'not done';
源文件是否存在于指定的位置

if( !file_exists( $currentpath ) ) echo 'Bad Foo - ' . $currentpath . ' not found!';

你需要得到你的真实路径,对我来说真实路径
/Applications/MAMP/htdocs/phptest
但是你可以定义
ABSPATH
define('ABSPATH',dirname(_文件__)。/')

完整代码:

 error_reporting(1);
 error_reporting('On');

define('ABSPATH', dirname(__FILE__).'/');

include 'includes/config.php';    // database configuration file

$file_name = "images800466507.jpg";
$currentPath = ABSPATH.'/TempImages/'.$file_name;    // ( file permission : 777 )
$newPath = ABSPATH.'/ImagesNew/'.$file_name;     // ( file permission : 755 )
if( rename($currentPath ,$newPath ) )
   echo 'done';
else
   echo 'not done';

我进行了测试,它对我起了作用。

你需要获得你的真实路径,对于我来说真实路径
/Applications/MAMP/htdocs/phptest
,但是你可以定义
ABSPATH
比如
define('ABSPATH',dirname('uuu FILE')/

完整代码:

 error_reporting(1);
 error_reporting('On');

define('ABSPATH', dirname(__FILE__).'/');

include 'includes/config.php';    // database configuration file

$file_name = "images800466507.jpg";
$currentPath = ABSPATH.'/TempImages/'.$file_name;    // ( file permission : 777 )
$newPath = ABSPATH.'/ImagesNew/'.$file_name;     // ( file permission : 755 )
if( rename($currentPath ,$newPath ) )
   echo 'done';
else
   echo 'not done';

我进行了测试,它对我有效。

tempmages/
之前添加
/
ImagesNew/
目录,如
/tempmages/
/ImagesNew/

<?php
    error_reporting(1);
    error_reporting('On');

    include 'includes/config.php';    // database configuration file

    //$site_path = "http://www.website.com/";

    $file_name = "images800466507.jpg";
    $currentPath = '/TempImages/'.$file_name;    // ( file permission : 777 )
    $newPath = '/ImagesNew/'.$file_name;      // ( file permission : 755 )

    if( rename($currentPath , $newPath ) )
        echo 'done';
    else
        echo 'not done';
?>


更多详细信息
rename
function

tempmages/
ImagesNew/
目录之前添加
/
,如
/tempmages/
/ImagesNew/

<?php
    error_reporting(1);
    error_reporting('On');

    include 'includes/config.php';    // database configuration file

    //$site_path = "http://www.website.com/";

    $file_name = "images800466507.jpg";
    $currentPath = '/TempImages/'.$file_name;    // ( file permission : 777 )
    $newPath = '/ImagesNew/'.$file_name;      // ( file permission : 755 )

    if( rename($currentPath , $newPath ) )
        echo 'done';
    else
        echo 'not done';
?>


更多详细信息
重命名
函数

您应该使用本地路径。本地路径的意思是。。???你说的是绝对路径吗/var/www/website.com/public_html/“本地路径”表示您的项目文件夹路径。非在线网站名称非
http://www.website.com
但更像是
/var/www/temp\u images/
或您的本地路径为“/var/www/website.com/public\u html/”的地方……????您应该使用本地路径。本地路径的意思是。。???你说的是绝对路径吗/var/www/website.com/public_html/“本地路径”表示您的项目文件夹路径。非在线网站名称非
http://www.website.com
但更像是
/var/www/temp_images/
或您的本地路径为“/var/www/website.com/public_html/”……的地方,我更新了代码,应该可以在现场工作,没有任何问题我更新了代码,它应该在现场工作,没有任何problem@ShanBiswas您是否尝试过像
$currentPath=ABSPATH./tempmages/.$FILE\u name您的问题下的所有3个答案都是正确的。我认为你的问题是另一个地方。@ShanBiswas你有没有试过像
$currentPath=ABSPATH./tempmages/.$FILE\u name您的问题下的所有3个答案都是正确的。我认为你的问题是另一个地方。