Laravel 5.3使用AJAX错误上传52张图像

Laravel 5.3使用AJAX错误上传52张图像

问题描述:

I have a problem. I'm using Bootstrap fileinput to upload 52 images with async AJAX requests. It uploads 90% of the files and randomly gives errors on few of the images.

This is the error:

SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)

Upload function:

public function uploadTemp360(Request $request)
{
    $image = $request->file('view360s');
    $fileName = $image->getClientOriginalName().'.'.$image->getClientOriginalExtension();
    $path = public_path().'/uploads/temp/';

    if ($image->isValid()){
        $image->move($path, $fileName);
    }

    return [
        'initialPreview' => [
            "<img  style='height:160px' src='/uploads/temp/".$fileName."' class='file-preview-image'>",
        ],
        'initialPreviewConfig' => [
            ['caption' => $fileName, 'width' => '120px', 'url' => route('admin.products.delete-temp-360'), 'key' => $fileName, 'size' => \File::size($path.$fileName)],
        ],
        'append' => true,
        'filename' => $fileName,
    ];
}

I don't know what's going on and how is it causing DB error by running this code...

I have found in laravel log this error: production.ERROR: exception 'RuntimeException' with message 'The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.'

我遇到了问题。 我正在使用Bootstrap fileinput上传52个带有异步AJAX请求的图像。 它上传了90%的文件并在少数图像上随机出现错误。 p>

这是错误: p>

SQLSTATE [HY000 ] [1045]用户“伪造”@“localhost”的访问被拒绝(使用密码:否) code> p>

上传功能: p>

   public function uploadTemp360(Request $ request)
 {
 $ image = $ request-&gt; file('view360s'); 
 $ fileName = $ image-&gt; getClientOriginalName()。'。'。$。  image-&gt; getClientOriginalExtension(); 
 $ path = public_path()。'/ uploads / temp /'; 
 
 if($ image-&gt; isValid()){
 $ image-&gt; move(  $ path,$ fileName); 
} 
 
返回[
'initialPreview'=&gt;  [
“&lt; img style ='height:160px'src ='/ uploads / temp /".$ fileName。”'class ='file-preview-image'&gt;“,
],
'initialPreviewConfig  '=&gt;  [
 ['caption'=&gt;  $ fileName,'width'=&gt;  '120px','url'=&gt;  route('admin.products.delete-temp-360'),'key'=&gt;  $ fileName,'size'=&gt;  \ File :: size($ path。$ fileName)],
],
'append'=&gt;  true,
'filename'=&gt;  $ fileName,
]; 
} 
  code>  pre> 
 
 

我不知道发生了什么,以及如何通过运行此代码导致数据库错误...

我在laravel中发现了这个错误: production.ERROR:异常'RuntimeException',带有消息'唯一支持的密码是AES-128-CBC和AES-256- 具有正确密钥长度的CBC。' code> p> div>

I have fixed that issue with running command: php artisan config:cache. It was problem because of Laravel can't read .env file sometimes...

It seems your database connection is being closed. Using following code you can keep you connection alive after each image upload.

DB::reconnect();

This could be a problem with the Laravel app key. Try executing these two commands in the following order using the command line from your projects root directory:

php artisan key:generate
php artisan config:clear

You can also try making sure that in your config/app.php file you have the following and try to clear the config again:

'cipher' => 'AES-128-CBC',