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