我正在創建一個應用程序,需要上傳文件,特別是視頻,我使用laravel來做服務器端的php。Laravel 4 - 上傳文件和SQL
我有一個表格上我的看法
{{ Form::open(array('route' => 'testuploads.store', 'files' => true, 'enctype' => 'multipart/form-data')) }}
<ul>
<li>
{{ Form::label('title', 'Title:') }}
{{ Form::text('title') }}
</li>
<li>
{{ Form::label('body', 'Body:') }}
{{ Form::textarea('body') }}
</li>
<li>
{{ Form::token() }}
{{ Form::label('file', 'File:') }}
{{ Form::file('file') }}
</li>
<li>
{{ Form::submit('Submit', array('class' => 'btn btn-info')) }}
</li>
</ul>
{{ Form::close() }}
控制器
public function store()
{
$input = Input::all();
$file = Input::file('file');
$pubpath = public_path();
$destinationPath = $pubpath.'/uploads/'.str_random(8);
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
// $path = $file->getRealPath();
$size = $file->getSize();
$mime = $file->getMimeType();
$uploadSuccess = Input::file('file')->move($destinationPath, $filename);
$validation = Validator::make($input, Testupload::$rules);
if ($validation->passes())
{
$this->testupload->create($input);
return Redirect::route('testuploads.index');
}
return Redirect::route('testuploads.create')
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors.');
}
我得到的錯誤是:
Symfony \ Component \ HttpFoundation \ File \ Exception \ FileException
Unable to create the "/www/test/public/uploads/xTzlVlxb" directory
我試圖權限更改爲上傳目錄,但沒有奏效。任何幫助表示感謝,謝謝。
'/ www/test/public/uploads /'可寫嗎? – JackPoint