How to upload file and save it with original name in storage folder












0















I want save uploaded file with original name.What i must add to this code?



Below's my code



public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$filename =$originalname;
$file->move('public/', $filename);
}









share|improve this question

























  • laravel.com/docs/5.5/requests#storing-uploaded-files

    – kerbholz
    Jan 2 at 8:06











  • how to use it? it give me error everytime i try it

    – Erwin Artha
    Jan 2 at 8:23













  • Checked the folder permissions? What error would that be? Can you please edit your question and paste the error there?

    – kerbholz
    Jan 2 at 8:26











  • "The file "C:xampptmpphpD2B2.tmp" does not exist" when i add $path = $request->image->store($originalname);

    – Erwin Artha
    Jan 2 at 8:28











  • $path = $request->photo->store('images'); ... "The store method accepts the path where the file should be stored relative to the filesystem's configured root directory." Is $originalname a path? Sounds more like a complete filename. "If you do not want a file name to be automatically generated, you may use the storeAs method, which accepts the path, file name, and disk name as its arguments"

    – kerbholz
    Jan 2 at 8:32
















0















I want save uploaded file with original name.What i must add to this code?



Below's my code



public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$filename =$originalname;
$file->move('public/', $filename);
}









share|improve this question

























  • laravel.com/docs/5.5/requests#storing-uploaded-files

    – kerbholz
    Jan 2 at 8:06











  • how to use it? it give me error everytime i try it

    – Erwin Artha
    Jan 2 at 8:23













  • Checked the folder permissions? What error would that be? Can you please edit your question and paste the error there?

    – kerbholz
    Jan 2 at 8:26











  • "The file "C:xampptmpphpD2B2.tmp" does not exist" when i add $path = $request->image->store($originalname);

    – Erwin Artha
    Jan 2 at 8:28











  • $path = $request->photo->store('images'); ... "The store method accepts the path where the file should be stored relative to the filesystem's configured root directory." Is $originalname a path? Sounds more like a complete filename. "If you do not want a file name to be automatically generated, you may use the storeAs method, which accepts the path, file name, and disk name as its arguments"

    – kerbholz
    Jan 2 at 8:32














0












0








0








I want save uploaded file with original name.What i must add to this code?



Below's my code



public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$filename =$originalname;
$file->move('public/', $filename);
}









share|improve this question
















I want save uploaded file with original name.What i must add to this code?



Below's my code



public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$filename =$originalname;
$file->move('public/', $filename);
}






php laravel laravel-5.5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 7:20







Erwin Artha

















asked Jan 2 at 7:15









Erwin ArthaErwin Artha

9




9













  • laravel.com/docs/5.5/requests#storing-uploaded-files

    – kerbholz
    Jan 2 at 8:06











  • how to use it? it give me error everytime i try it

    – Erwin Artha
    Jan 2 at 8:23













  • Checked the folder permissions? What error would that be? Can you please edit your question and paste the error there?

    – kerbholz
    Jan 2 at 8:26











  • "The file "C:xampptmpphpD2B2.tmp" does not exist" when i add $path = $request->image->store($originalname);

    – Erwin Artha
    Jan 2 at 8:28











  • $path = $request->photo->store('images'); ... "The store method accepts the path where the file should be stored relative to the filesystem's configured root directory." Is $originalname a path? Sounds more like a complete filename. "If you do not want a file name to be automatically generated, you may use the storeAs method, which accepts the path, file name, and disk name as its arguments"

    – kerbholz
    Jan 2 at 8:32



















  • laravel.com/docs/5.5/requests#storing-uploaded-files

    – kerbholz
    Jan 2 at 8:06











  • how to use it? it give me error everytime i try it

    – Erwin Artha
    Jan 2 at 8:23













  • Checked the folder permissions? What error would that be? Can you please edit your question and paste the error there?

    – kerbholz
    Jan 2 at 8:26











  • "The file "C:xampptmpphpD2B2.tmp" does not exist" when i add $path = $request->image->store($originalname);

    – Erwin Artha
    Jan 2 at 8:28











  • $path = $request->photo->store('images'); ... "The store method accepts the path where the file should be stored relative to the filesystem's configured root directory." Is $originalname a path? Sounds more like a complete filename. "If you do not want a file name to be automatically generated, you may use the storeAs method, which accepts the path, file name, and disk name as its arguments"

    – kerbholz
    Jan 2 at 8:32

















laravel.com/docs/5.5/requests#storing-uploaded-files

– kerbholz
Jan 2 at 8:06





laravel.com/docs/5.5/requests#storing-uploaded-files

– kerbholz
Jan 2 at 8:06













how to use it? it give me error everytime i try it

– Erwin Artha
Jan 2 at 8:23







how to use it? it give me error everytime i try it

– Erwin Artha
Jan 2 at 8:23















Checked the folder permissions? What error would that be? Can you please edit your question and paste the error there?

– kerbholz
Jan 2 at 8:26





Checked the folder permissions? What error would that be? Can you please edit your question and paste the error there?

– kerbholz
Jan 2 at 8:26













"The file "C:xampptmpphpD2B2.tmp" does not exist" when i add $path = $request->image->store($originalname);

– Erwin Artha
Jan 2 at 8:28





"The file "C:xampptmpphpD2B2.tmp" does not exist" when i add $path = $request->image->store($originalname);

– Erwin Artha
Jan 2 at 8:28













$path = $request->photo->store('images'); ... "The store method accepts the path where the file should be stored relative to the filesystem's configured root directory." Is $originalname a path? Sounds more like a complete filename. "If you do not want a file name to be automatically generated, you may use the storeAs method, which accepts the path, file name, and disk name as its arguments"

– kerbholz
Jan 2 at 8:32





$path = $request->photo->store('images'); ... "The store method accepts the path where the file should be stored relative to the filesystem's configured root directory." Is $originalname a path? Sounds more like a complete filename. "If you do not want a file name to be automatically generated, you may use the storeAs method, which accepts the path, file name, and disk name as its arguments"

– kerbholz
Jan 2 at 8:32












2 Answers
2






active

oldest

votes


















0














Try this:



if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$img = Image::make($file->getRealPath());
$img->stream();
Storage::disk('local')->put('images/'.$originalname, $img, 'public');
}





share|improve this answer
























  • Error "Class 'AppHttpControllersImage' not found"

    – Erwin Artha
    Jan 2 at 11:16











  • Please add use Image; on top of your controller

    – user10186369
    Jan 2 at 11:27











  • Still error Class image not found

    – Erwin Artha
    Jan 2 at 11:56











  • In your app.php Add this in your aliases: "'Image' => InterventionImageFacadesImage::class," and in your providers "InterventionImageImageServiceProvider::class," Don't forget to do php artisan config:cache after this.

    – user10186369
    Jan 2 at 12:38





















0














You may use the storeAs method, which receives the path, the file name, and the (optional) disk as its arguments:



public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$path = $file->storeAs('public/', $originalname);
}
}





share|improve this answer


























  • Error "Call to a member function hashName() on string"

    – Erwin Artha
    Jan 2 at 11:17











  • edited my answer.

    – DPS
    Jan 3 at 5:21











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002591%2fhow-to-upload-file-and-save-it-with-original-name-in-storage-folder%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try this:



if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$img = Image::make($file->getRealPath());
$img->stream();
Storage::disk('local')->put('images/'.$originalname, $img, 'public');
}





share|improve this answer
























  • Error "Class 'AppHttpControllersImage' not found"

    – Erwin Artha
    Jan 2 at 11:16











  • Please add use Image; on top of your controller

    – user10186369
    Jan 2 at 11:27











  • Still error Class image not found

    – Erwin Artha
    Jan 2 at 11:56











  • In your app.php Add this in your aliases: "'Image' => InterventionImageFacadesImage::class," and in your providers "InterventionImageImageServiceProvider::class," Don't forget to do php artisan config:cache after this.

    – user10186369
    Jan 2 at 12:38


















0














Try this:



if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$img = Image::make($file->getRealPath());
$img->stream();
Storage::disk('local')->put('images/'.$originalname, $img, 'public');
}





share|improve this answer
























  • Error "Class 'AppHttpControllersImage' not found"

    – Erwin Artha
    Jan 2 at 11:16











  • Please add use Image; on top of your controller

    – user10186369
    Jan 2 at 11:27











  • Still error Class image not found

    – Erwin Artha
    Jan 2 at 11:56











  • In your app.php Add this in your aliases: "'Image' => InterventionImageFacadesImage::class," and in your providers "InterventionImageImageServiceProvider::class," Don't forget to do php artisan config:cache after this.

    – user10186369
    Jan 2 at 12:38
















0












0








0







Try this:



if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$img = Image::make($file->getRealPath());
$img->stream();
Storage::disk('local')->put('images/'.$originalname, $img, 'public');
}





share|improve this answer













Try this:



if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$img = Image::make($file->getRealPath());
$img->stream();
Storage::disk('local')->put('images/'.$originalname, $img, 'public');
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 9:56







user10186369




















  • Error "Class 'AppHttpControllersImage' not found"

    – Erwin Artha
    Jan 2 at 11:16











  • Please add use Image; on top of your controller

    – user10186369
    Jan 2 at 11:27











  • Still error Class image not found

    – Erwin Artha
    Jan 2 at 11:56











  • In your app.php Add this in your aliases: "'Image' => InterventionImageFacadesImage::class," and in your providers "InterventionImageImageServiceProvider::class," Don't forget to do php artisan config:cache after this.

    – user10186369
    Jan 2 at 12:38





















  • Error "Class 'AppHttpControllersImage' not found"

    – Erwin Artha
    Jan 2 at 11:16











  • Please add use Image; on top of your controller

    – user10186369
    Jan 2 at 11:27











  • Still error Class image not found

    – Erwin Artha
    Jan 2 at 11:56











  • In your app.php Add this in your aliases: "'Image' => InterventionImageFacadesImage::class," and in your providers "InterventionImageImageServiceProvider::class," Don't forget to do php artisan config:cache after this.

    – user10186369
    Jan 2 at 12:38



















Error "Class 'AppHttpControllersImage' not found"

– Erwin Artha
Jan 2 at 11:16





Error "Class 'AppHttpControllersImage' not found"

– Erwin Artha
Jan 2 at 11:16













Please add use Image; on top of your controller

– user10186369
Jan 2 at 11:27





Please add use Image; on top of your controller

– user10186369
Jan 2 at 11:27













Still error Class image not found

– Erwin Artha
Jan 2 at 11:56





Still error Class image not found

– Erwin Artha
Jan 2 at 11:56













In your app.php Add this in your aliases: "'Image' => InterventionImageFacadesImage::class," and in your providers "InterventionImageImageServiceProvider::class," Don't forget to do php artisan config:cache after this.

– user10186369
Jan 2 at 12:38







In your app.php Add this in your aliases: "'Image' => InterventionImageFacadesImage::class," and in your providers "InterventionImageImageServiceProvider::class," Don't forget to do php artisan config:cache after this.

– user10186369
Jan 2 at 12:38















0














You may use the storeAs method, which receives the path, the file name, and the (optional) disk as its arguments:



public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$path = $file->storeAs('public/', $originalname);
}
}





share|improve this answer


























  • Error "Call to a member function hashName() on string"

    – Erwin Artha
    Jan 2 at 11:17











  • edited my answer.

    – DPS
    Jan 3 at 5:21
















0














You may use the storeAs method, which receives the path, the file name, and the (optional) disk as its arguments:



public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$path = $file->storeAs('public/', $originalname);
}
}





share|improve this answer


























  • Error "Call to a member function hashName() on string"

    – Erwin Artha
    Jan 2 at 11:17











  • edited my answer.

    – DPS
    Jan 3 at 5:21














0












0








0







You may use the storeAs method, which receives the path, the file name, and the (optional) disk as its arguments:



public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$path = $file->storeAs('public/', $originalname);
}
}





share|improve this answer















You may use the storeAs method, which receives the path, the file name, and the (optional) disk as its arguments:



public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$path = $file->storeAs('public/', $originalname);
}
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 5:21

























answered Jan 2 at 9:53









DPSDPS

501415




501415













  • Error "Call to a member function hashName() on string"

    – Erwin Artha
    Jan 2 at 11:17











  • edited my answer.

    – DPS
    Jan 3 at 5:21



















  • Error "Call to a member function hashName() on string"

    – Erwin Artha
    Jan 2 at 11:17











  • edited my answer.

    – DPS
    Jan 3 at 5:21

















Error "Call to a member function hashName() on string"

– Erwin Artha
Jan 2 at 11:17





Error "Call to a member function hashName() on string"

– Erwin Artha
Jan 2 at 11:17













edited my answer.

– DPS
Jan 3 at 5:21





edited my answer.

– DPS
Jan 3 at 5:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54002591%2fhow-to-upload-file-and-save-it-with-original-name-in-storage-folder%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory