Laravel - How to change upload file path

2019-09-19 08:40发布

I need to upload images to folder project images.

My project structure folder in share host is this:

- css
- images
- fonts
- js
- laravel-code
- .htaccess

Inside laravel-code folder are the remaining files.

The site work well, show images well but when i upload a new image it save the image in laravel-code/ and create this folders public/images ...

I want to save images in image folder at root directory.

How can I do that?

When I do an upload file it detects if it was a pdf or other file; if it was pdf saves file on storage folder, if it other file (images) save in images folder. This is my code... I think I cannot use public_path

if (false === stripos($name, '-pdf')) {
    $basePath = trim(public_path(), '/');
    $newPath = trim(public_path('images'), '/');
} else {
    $basePath = trim(storage_path(), '/');
    $newPath = trim(storage_path(), '/');
}

1条回答
戒情不戒烟
2楼-- · 2019-09-19 09:14

To get the full path to the parent of the root directory, you will need to use PHP's built in dirname function.

The first argument indicates the directory to be evaluated. The second argument is the level of parent directories you want to traverse, in your example, only one level up.

$root = base_path();
$parent = dirname($root, 1); 
查看更多
登录 后发表回答