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);
}
}
当我死的时候(var_dump(Input::file('profile'))返回null,这意味着它基本上不会将我的文件作为实际文件接收.当我死(var_dump(Input::get('profile'))时,它返回图像名,这意味着我的上传脚本正在工作,但Laravel后端失败.这是真的,还是我错过了什么?
以下是我的HTML表单:
@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