Move image from one folder to another folder in php

I use Laravel 5.3

When I upload image, I save the image in :

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

My code to save the image like this :

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

When I click button submit, I want to move the image from folder storage to folder public

So I want to move the image in :

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

How can I move the image in folder public?

September 6, 2020 Category : PHP

In this short tutorial we will cover an php move file from one folder to another. i would like to share with you move image from one folder to another in php. you will learn move a file from one folder to another folder in php. if you have question about how to move file from one folder to another in php then i will give simple example with solution.

If you need to move file from one folder to another using php code then we can use "rename[]" function of php. php provide rename function to move your file from one place to another.

So, here i will give you very simple example and syntax how it works to move file from one folder to another in php.

Let's see bellow syntax and example that will help you.

Syntax:

bool rename[ string $source, string $destination, resource $context ]

You can see bellow parameter in details:

$source: you need to give file path that you want to rename.

$destination: you need to give file path for destination source.

$context: this is optional, It specifies the context resource created with stream_context_create[] function.

Example:

Chủ Đề