Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.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,在使用basename()获取文件名后,我正在尝试重命名文件。我收到一个错误,提示“找不到指定的文件”。 我的代码是: $target_dir = "uploads/"; $base_name = basename($_FILES["file_to_upload"]["name"]); $target_file = $target_dir.$base_name;//specifies the path of the file to b

在使用basename()获取文件名后,我正在尝试重命名文件。我收到一个错误,提示“找不到指定的文件”。 我的代码是:

$target_dir = "uploads/";

$base_name = basename($_FILES["file_to_upload"]["name"]);
$target_file = $target_dir.$base_name;//specifies the path of the file to be 
uploaded.
$image_extention = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));

//rename the file
$rename_file_name = rename($base_name,'Image_1');
dd($rename_file_name);
运行代码时,出现以下错误:


警告:重命名(RageFace.jpg,Image_1):系统找不到指定的文件。(代码:2)在C:\xampp\htdocs\pdo\file_upload_handle.php的第23行

布尔(假)

试一试

移动时更改名称

move_uploaded_file($_FILES["file_to_upload"]["tmp_name"],$target_file);

您是否尝试过使用文件的完整路径而不是仅使用
basename()
?如果您这样做会显示您需要提供文件的完整路径而不仅仅是文件名,除非文件恰好位于当前工作目录中,这对于上载的文件是不明智的“系统无法找到指定的文件”我似乎很清楚。检查你的路径。@kerbholz我以前没有试着给出完整的路径,我现在已经给出了,它正在工作。@Martin谢谢。你的评论帮助我理解了问题和我的错误。