Laravel文件上传混乱 - php

因此,我试图与Laravel框架内的旧文件上传进行斗争,但有点迷路。我设法使上传生效,因此文件上传并以随机字符串名称保存到资产文件夹中。

形式如下:

<form action="{{ URL::route('account-upload') }}" method="post">
{{ Form::label('file','Upload File') }}
{{ Form::file('file') }}
<br />
{{ Form::submit('Upload') }}
{{ Form::token() }}
</form>

这是路线:

Route::get('/account/upload', array(
    'as' => 'account-upload',
    'uses' => 'AccountController@getUpload'
));


    Route::post('/account/upload', function(){

        if (Input::hasFile('file')){
            $dest = 'assets/uploads/';
            $name = str_random(6).'_'. Input::file('file')->getClientOriginalName();
            Input::file('file')->move($dest,$name);

            return Redirect::to('/account/upload')
                ->withGlobal('Your image has been uploaded');
        }

    });

这是AccountController内部的方法:

public function getUpload(){
    return View::make('account.upload');
}

public function postUpload() {
     $user  = User::find(Auth::id());
     $user->image  = Input::get('file');
}

我现在正在尝试启用该功能以将字符串名称推送到数据库中,并与上载该字符串名称并显示为个人资料图像的用户相关联?指针会很棒!

我已经在数据库内部创建了一个名为“文件”的行,其文本类型为...。我不确定如何存储和查看图像。

参考方案

试试这个

// the view
{{ Form::open(['route' => 'account-upload', 'files' => true]) }}
    {{ Form::label('file','Upload File') }}
    {{ Form::file('file') }}
    <br />
    {{ Form::submit('Upload') }}
{{ Form::close() }}


// route.php
Route::get('/account/upload', 'AccountController@upload');

Route::post('/account/upload', [
    'as'   => 'account-upload',
    'uses' => 'AccountController@store'
]);


// AccountController.php
class AccountController extends BaseController {

    public function upload(){
        return View::make('account.upload');
    }

    public function store() {
        if (Input::hasFile('file')){

            $file = Input::file('file');
            $dest = public_path().'/assets/uploads/';
            $name = str_random(6).'_'. $file->getClientOriginalName();

            $file->move($dest,$name);

            $user      = User::find(Auth::id());
            $user->image  = $name;
            $user->save();

            return Redirect::back()
                ->withGlobal('Your image has been uploaded');
        }
    }
}

// and to display the img on the view
<img src="assets/upload/{{Auth::user()->image}}"/>

验证IBAN PHP - php

在设计新平台时,我们尝试集成IBAN编号。我们必须确保IBAN已经过验证,并且存储在数据库中的IBAN始终正确。那么验证数字的正确方法是什么? 参考方案 正如我在其他问题中解释的逻辑一样,我尝试自己创建一个函数。根据Wikipedia文章中解释的逻辑,在下面找到合适的功能。国家特定验证。它适合吗http://en.wikipedia.org/wiki/Int…

File_exists但不包含 - php

我正在尝试包含一个文件,但它似乎无法正常工作-这是整个代码:if (file_exists('config/categories.php')) { include ('config/categories.php'); } foreach ($categories as $cat_sef => $cat_name)…

PHP:对数组排序 - php

请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…

PHP:不推荐使用password_hash的'salt'选项 - php

我正在使用密码哈希进行注册。我需要手动创建Salt,以下是我使用的代码:$options = [ 'cost' => 11, 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM) ]; $password = password_hash( $this->…

如何在PHP中设置get_file_contents的时间限制? - php

有时get_file_contents花费的时间太长,这会挂起整个脚本。有什么方法可以设置get_file_contents的超时限制,而无需修改脚本的最大执行时间?编辑:由于该文件不存在,因此花费了很长时间。我收到“无法打开流:HTTP请求失败!”错误。但这需要永远。 参考方案 通过使用timeout option创建上下文,似乎在PHP> 5.2.…