Support the ongoing development of Laravel.io →
Requests Input Forms

I am trying to upload a photo with Request::file('file')->move('location/file.type');

But it doesn't seem work, it creates new folder with the name of the file. Not upload the file.

I got really confused of this because in another controller it works very well with the same code.

Here is the controller:

/*
* upload the avatar
*/

if ($request->hasFile('avatar')){
	$file = $request->file('avatar');

	$name = str_random(15).".{$file->getClientOriginalExtension()}";

	// cek if the name already exists
	while (\File::exists("images/travelagents/avatar/{$name}")){
		$name = str_random(10).'.'.$file->getClientOriginalExtension();
	}

	$file->move("images/travelagents/avatar/{$name}");

	$travelAgent->avatar = $name;
}

$travelAgent->save();

and the result was:

Your alt text here

###when i change the code

/*
* upload the avatar
*/

if ($request->hasFile('avatar')){
	$file = $request->file('avatar');

	$name = "test.{$file->getClientOriginalExtension()}";

	$file->move("images/travelagents/avatar/{$name}");

	$travelAgent->avatar = $name;
}

$travelAgent->save();

And the result:

Your alt text here

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

hudasanca hudasanca Joined 19 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.