php - Laravel - How to change upload file path
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
Insidelaravel-code
folder are the remaining files.
The site work well, show images well but when i upload a new image it save the image inlaravel-code/
and create this folderspublic/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 usepublic_path
if (false === stripos($name, '-pdf')) {
$basePath = trim(public_path(), '/');
$newPath = trim(public_path('images'), '/');
} else {
$basePath = trim(storage_path(), '/');
$newPath = trim(storage_path(), '/');
}
Answer
Solution:
To get the full path to the parent of the root directory, you will need to use PHP's built in
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.