我写了以下基本文件上传代码,在localhost上完美运行。在实时版本中,Input::hasFile('profile_picture')
返回false,因此文件未移至所需目录,而$filename = Input::file('profile_picture')->getClientOriginalName();
正常工作并收到文件名。
在移动文件之前删除if hasFile检查,移动函数抛出异常说,
Symfony \ Component \ HttpFoundation \ File \ Exception \ FileException
File could not be uploaded: missing temporary directory.
我已确认:
ini_set('memory_limit', '128M');
中的index.php
。'files' => true
和csrf令牌。upload.blade.php包含:
{{ Form::open(['url' => 'api/users', 'files' => true]) }}
File: {{ Form::file('profile_picture') }}
{{ Form::hidden('email', 'asimawan.62@gmail.com') }}
{{ Form::submit('send') }}
{{ Form::close() }}
生成的表单如下:
<form method="POST" action="http://localhost:8000/api/users" accept-charset="UTF-8" enctype="multipart/form-data"><input name="_token" type="hidden" value="96OKRdiwnHlku0uMLYYpHPjAIKAiqoKRp372fUWc">
File: <input name="profile_picture" type="file">
<input name="email" type="hidden" value="asimawan.62@gmail.com">
<input type="submit" value="send">
</form>
routes.php包含:
Route::get('upload', function() {
return View::make('upload');
});
Route::resource('api/users', 'UsersController');
UsersController ::存储()
public function store()
{
if ($this->user->isValid($data = Input::all())) {
$data = Input::all();
$filename = Input::file('profile_picture')->getClientOriginalName();
$data['profile_picture'] = $filename;
if (Input::hasFile('profile_picture')) {
Input::file('profile_picture')->move(public_path('pictures/profile'), $filename);
} else {
return "Input::hasFile('profile_picture') has returned false. Size = "
. Input::file('profile_picture')->getClientSize();
}
$this->user->fill($data);
$this->user->save();
return Response::json($this->user);
}
return Response::json($this->user->errors);
}
答案 0 :(得分:2)
看起来像是服务器上的权限问题。
尝试这个php函数来知道临时文件的路径是什么
ini_get('upload_tmp_dir');
然后,检查文件夹的权限。