使用Laravel损坏的Jpg文件上传

时间:2014-05-16 01:13:12

标签: php image laravel upload corruption

这是一个令人讨厌的人:glitchburger

这应该是一张汉堡包的照片。这很酷,但是我上传它之后还需要它成为一个汉堡包,否则客户会很生气。

我正在使用laravel 4而且没什么特别的。下面是我的代码,或多或少地从某个教程中抄袭 - 任何想法是怎么回事?不幸的是,我真的无法启动另一个托管环境来测试。

上传表单:

{{ Form::open(array('url'=>'/manage/photos/upload', 'class'=>'form-signin',  'files' => true)) }}   
    {{ Form::file('image') }}
    {{ Form::submit('Upload Photos', array('class'=>'btn btn-large btn-primary btn-block'))}}
{{ Form::close() }}

文件在我的控制器中接收代码:

    public function uploadPhoto() {
        $file = Input::file('image');
        $input = array('image' => $file);
        $rules = array(
            'image' => 'image'
        );
        $validator = Validator::make($input, $rules);
        if ( $validator->fails() )
        {
            return Redirect::to('/manage/photos')->with('message', 'There was a problem:');
        } else {
            $destinationPath = 'profileimages';
            $filename = uniqid('', true).'.jpg';    
            Input::file('image')->move($destinationPath, $filename);

            return Redirect::back()->with('message', 'The photo was successfully uploaded');
        }
    }

任何想法?

0 个答案:

没有答案
相关问题