I've been writing an uploading script and even though I'm using the Laravel built in function Input::file() it still returns null. I am going to post my Home Controller code.
public function handleUpload()
{
$user = Auth::user();
$username = $user->username;
$userId = $user->id;
$path_to_users = "users";
$user_profile_img = 'users/'.$username.$userId.'/'.$username.'image001.jpg';
$user_path_profile = "users/$username$userId";
$user_image_name = $username.'image001.jpg';
if(file_exists($path_to_users))
{
if(file_exists("$user_path_profile")){
$file = Input::file('profile')->move("$user_path_profile/", $user_image_name);
} else {
mkdir("$user_path_profile");
$file = Input::file('profile')->move("$user_path_profile/", $user_image_name);
}
} else {
mkdir("users");
mkdir("$user_path_profile");
$file = Input::file('profile')->move("$user_path_profile/", $user_image_name);
}
}
When I die(var_dump(Input::file('profile'))) returns null which means it is basically not taking in my file as an actual file. When I do die(var_dump(Input::get('profile'))) it returns the image name meaning that my uploading script is working but the Laravel backend is failing. Is this true, or am I just missing something?
Here is my HTML form stuff:
@if($user->id == $userProf->id)
<div class="fileUpload button-success pure-button">
<span>Upload</span>
<form action="{{action('HomeController@handleUpload')}}" method="POST" enctype="multipart/form-data">
<input type="file" name="profile" class="upload" />
</form>
</div>
@endif