简体   繁体   中英

Laravel: Array to string conversion while uploading .sql files

Edit: It turns out this issue happens while trying to upload .sql files. It's not the file name.

When I try to upload a file with this name: forge_2016-02-08_--USERS THOUGH.sql I'm shown this error below:

ErrorException in FileinfoMimeTypeGuesser.php line 69:

Array to string conversion

and

at HandleExceptions->handleError('8', 'Array to string conversion', '/home/forge/example.com/vendor/symfony/http-foundation/File/MimeType/FileinfoMimeTypeGuesser.php', '69', array('path' => '/tmp/phppkDGK8', 'finfo' => object(finfo)))

at finfo->file('/tmp/phppkDGK8') in FileinfoMimeTypeGuesser.php line 69

at finfo->file('/tmp/phppkDGK8') in FileinfoMimeTypeGuesser.php line 69 at FileinfoMimeTypeGuesser->guess('/tmp/phppkDGK8') in MimeTypeGuesser.php line 139

I have no idea why this error is happening. Here's my upload code:

    $baseDir = storage_path('uploads');

    $file = $request->file('file');
    $mimeType = $file->getMimeType();
    $name = str_random(6) . time() . '-' . str_replace(' ', '_', Str::ascii($file->getClientOriginalName()));
    $file->move($baseDir, $name);

    $path = $baseDir . '/' . $name;
    $data = ['path' => $path, 'ip' => userIP(), 'name' => $file->getClientOriginalName(), 'mime' => $mimeType, 'size' => $file->getClientSize()];
    $status = Uploads::create($data);

    if ($status) {
          $su = true;

Please help guys. I don't know why this is happening.

I fixed it by changing

$mimeType = $file->getMimeType(); 

to

$mimeType = $file->getClientMimeType();

This fixed it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM