Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.2-将文件上载到数据库_Php_Database_Laravel_File Upload_Laravel 5.2 - Fatal编程技术网

Php Laravel 5.2-将文件上载到数据库

Php Laravel 5.2-将文件上载到数据库,php,database,laravel,file-upload,laravel-5.2,Php,Database,Laravel,File Upload,Laravel 5.2,这些就是我所拥有的: ErrorException in ParameterBag.php line 90: array_key_exists(): The first argument should be either a string or an integer 名为lamanInformasi,包含以下字段的数据库表:id,judul,isi,在处创建,在处更新 这就是我想要的: ErrorException in ParameterBag.php line 90: array_key_

这些就是我所拥有的:

ErrorException in ParameterBag.php line 90:
array_key_exists(): The first argument should be either a string or an integer
名为
lamanInformasi
,包含以下字段的数据库表:
id
judul
isi
处创建,
处更新

这就是我想要的:

ErrorException in ParameterBag.php line 90:
array_key_exists(): The first argument should be either a string or an integer
用户可以上传多个文档或图像文件,这些文件将存储到数据库中。文件名将保存到
isi
字段,文件本身将保存到名为
propic
的文件夹中。用户还可以在网站上显示数据库中的所有数据

这些是我的代码:

ErrorException in ParameterBag.php line 90:
array_key_exists(): The first argument should be either a string or an integer
create.blade.php

index.blade.php

我在参数包第89-91行有这个

public function get($key, $default = null)
{
    return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
}
以下是我的问题:

ErrorException in ParameterBag.php line 90:
array_key_exists(): The first argument should be either a string or an integer

如何修复该错误?我上传文件的代码正确吗?因为我尝试过类似的代码,但它不起作用。谢谢

有几件事你需要处理。请尝试下面的代码

LamanInformasiController.php-控制器名称通常大写

class LamanInformasiController extends Controller
{
    /**
     * @var LamanInformasi - include the use statement above for the model.
     */
    protected $model;

    /**
     * Inject (model)LamanInformasi while instantiating the controller.
     * @param LamanInformasi $model
     */
    public function __construct(LamanInformasi $model)
    {
        $this->model = $model;
    }

    public function index()
    { 
        $lamanInformasi = $this->model->all();
        return view('upload.index', compact('lamanInformasi'));
    }


    public function store(Request $request)
    {
        if (Input::hasFile('image'))
        {
            $destinationPath = public_path().'/propic/';
            $name = Input::file('image')->getClientOriginalName();
            $extension = Input::file('image')->getClientOriginalExtension();
            $fileName = $name.'.'.$extension;

            //store the file in the $destinationPath
            $file = Input::file('image')->move($destinationPath, $fileName);

            //save a corresponding record in the database
            $this->model->create(['isi'=> $fileName]);

            //return success message
        } 
        //return failure message
    }

}   //don't forget to include the use statement for Input or write \Input
然后在index.blade.php中

<table class="table table-striped table-bordered" border= "1px solid black">
<thead>
    <tr>
        <td>ID</td>
        <td>Judul</td>
        <td>Isi</td>
        <td>Created At</td>
        <td>Updated At</td>
    </tr>
</thead>
<tbody>
    @foreach($lamanInformasi as $file)
    <tr>
        <td>{{$file->id}}</td>
        <td>{{$file->judul}}</td>
        <td>{{$file->isi}}</td>
        <td>{{$file->created_at}}</td>
        <td>{{$file->updated_at}}</td>
     </tr>
     @endforeach
</tbody>

身份证件
朱杜尔
三军情报局
创建于
更新于
@foreach($lamaniformasi作为$file)
{{$file->id}
{{$file->judul}
{{$file->isi}
{{$file->created_at}
{{$file->updated_at}
@endforeach

你的行动应该是相应的

<form action="/upload8" method="post" enctype="multipart/form-data">
<input type="file" name="image"><br />
<input type="submit" name="submit" value="Submit">



这应该是可行的,但还没有测试过。如果不是,请告诉我。

有几件事你需要处理。请尝试下面的代码

LamanInformasiController.php-控制器名称通常大写

class LamanInformasiController extends Controller
{
    /**
     * @var LamanInformasi - include the use statement above for the model.
     */
    protected $model;

    /**
     * Inject (model)LamanInformasi while instantiating the controller.
     * @param LamanInformasi $model
     */
    public function __construct(LamanInformasi $model)
    {
        $this->model = $model;
    }

    public function index()
    { 
        $lamanInformasi = $this->model->all();
        return view('upload.index', compact('lamanInformasi'));
    }


    public function store(Request $request)
    {
        if (Input::hasFile('image'))
        {
            $destinationPath = public_path().'/propic/';
            $name = Input::file('image')->getClientOriginalName();
            $extension = Input::file('image')->getClientOriginalExtension();
            $fileName = $name.'.'.$extension;

            //store the file in the $destinationPath
            $file = Input::file('image')->move($destinationPath, $fileName);

            //save a corresponding record in the database
            $this->model->create(['isi'=> $fileName]);

            //return success message
        } 
        //return failure message
    }

}   //don't forget to include the use statement for Input or write \Input
然后在index.blade.php中

<table class="table table-striped table-bordered" border= "1px solid black">
<thead>
    <tr>
        <td>ID</td>
        <td>Judul</td>
        <td>Isi</td>
        <td>Created At</td>
        <td>Updated At</td>
    </tr>
</thead>
<tbody>
    @foreach($lamanInformasi as $file)
    <tr>
        <td>{{$file->id}}</td>
        <td>{{$file->judul}}</td>
        <td>{{$file->isi}}</td>
        <td>{{$file->created_at}}</td>
        <td>{{$file->updated_at}}</td>
     </tr>
     @endforeach
</tbody>

身份证件
朱杜尔
三军情报局
创建于
更新于
@foreach($lamaniformasi作为$file)
{{$file->id}
{{$file->judul}
{{$file->isi}
{{$file->created_at}
{{$file->updated_at}
@endforeach

你的行动应该是相应的

<form action="/upload8" method="post" enctype="multipart/form-data">
<input type="file" name="image"><br />
<input type="submit" name="submit" value="Submit">



这应该是可行的,但还没有测试过。如果不是,请告诉我。

数组\u key\u的存在方式处理null、float、boolean和“表示字符串的整数”键本身是不一致的,对于bool和float,它们在用作数组偏移量时的转换方式也是不一致的。@FullStack抱歉,我不理解。我该怎么办?看看这个页面@FullStack,我仍然不明白我的参数有什么问题。array_key_处理null、float、boolean和“integer representation string”键的方式本身是不一致的,对于bool和float,它们在用作数组偏移量时的转换方式也是不一致的。@FullStack抱歉,我不明白。我该怎么办?看看这个页面@FullStack我仍然不明白我的参数出了什么问题,我犯了一个错误。我应该把代码放在
lamaniformasicontroller
中的
index
函数中,以
store
函数,所以我移动了它。它工作正常,直到我选择一个文件并单击Submit,我在RouteCollection.php第161行中出现了这个错误,
NotFoundHttpException
routes.php中出现了这个错误(“/upload8”,“LamaniFormasicController”)如果您使用的是
Route::resource
,那么您应该遵循REST惯例,在
LamaniFormasiController
store
方法中处理上传文件的存储,并更改表单action。您能给出正确的代码吗?我不知道我必须更改的是哪一部分,
表单操作
转到错误的URL。我使用以下URL访问表单:
http://localhost/wfpProject/public/upload8
。当我单击提交时,它会将我带到以下URL:
http://localhost/upload8
我犯了一个错误。我应该把代码放在
lamaniformasicontroller
中的
index
函数中,以
store
函数,所以我移动了它。它工作正常,直到我选择一个文件并单击Submit,我在RouteCollection.php第161行中出现了这个错误,
NotFoundHttpException
routes.php中出现了这个错误(“/upload8”,“LamaniFormasicController”)如果您使用的是
Route::resource
,那么您应该遵循REST惯例,在
LamaniFormasiController
store
方法中处理上传文件的存储,并更改表单action。您能给出正确的代码吗?我不知道我必须更改的是哪一部分,
表单操作
转到错误的URL。我使用以下URL访问表单:
http://localhost/wfpProject/public/upload8
。当我单击提交时,它会将我带到以下URL:
http://localhost/upload8