如何将图像从一个文件夹移动到另一个文件夹?

How can I move an image from one folder to another folder?

我用Laravel 5.3

当我上传图片时,我将图片保存在:

C:\xampp\htdocs\myshop\storage\temp

我的代码是这样保存图像的:

private function addPhoto(UploadedFile $photo, $fileName)
{
    $destinationPath = storage_path() . DIRECTORY_SEPARATOR . 'temp';
    $photo->move($destinationPath, $fileName);
    return $fileName;
}

当我点击按钮提交时,我想将图像从文件夹存储移动到文件夹 public

所以我想把图片移到:

C:\xampp\htdocs\myshop\public\img

如何移动文件夹 public 中的图像?

看看 rename 函数。 尝试这样的事情:

$org_image="C:\xampp\htdocs\myshop\storage\temp\xxxx.jpg";
$destination="C:\xampp\htdocs\myshop\public\img";

$img_name=basename($org_image);

if( rename( $org_image , $destination.'/'.$img_name )){
 echo 'moved!';
} else {
 echo 'failed';
}