I'm trying copy an image to storage/app/uploads
folder using the following code:
public function save(Request $request)
{
$arrayName = array();
echo "<pre>";
print_r($request->all());
echo "</pre>";
$image = $request->file('image');
$name = $imagem->getClientOriginalName();
$ext = $imagem->getClientOriginalExtension();
$newName = str_replace(' ','_', $imagem->getClientOriginalName());
$destinationPath = 'uploads';
//$path = $imagem->store($newName);
$path = $imagem->storeAs($destinationPath, $newName);
echo "<pre>";
print_r($path);
echo "</pre>";
}
The result from code above is:
Array
(
[id] =>
[description] => description
[title] => title
[title_small] => title_small
[text] => text
[image] => Illuminate\Http\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => manaus1.png
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => application/octet-stream
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 1
[hashName:protected] =>
[pathName:SplFileInfo:private] =>
[fileName:SplFileInfo:private] =>
)
[published] => S
)
But when I open what has been saved, it open a text document with the original extension.
I want save the right way.
I advise you to use this :
I'm saving with this code
Please try this and let me know how it works. :)