Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.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,旋转图像要求参数为有效路径_Php_Mysql_Laravel_Laravel 5_File Read - Fatal编程技术网

Php Laravel,旋转图像要求参数为有效路径

Php Laravel,旋转图像要求参数为有效路径,php,mysql,laravel,laravel-5,file-read,Php,Mysql,Laravel,Laravel 5,File Read,当我将图像上传到数据库时,Laravel会旋转它们,所以我发现 ,然后在实现它之后,我得到这个错误exif\u read\u data()期望参数1是一个有效的路径,数组给定。我怎样才能解决这个问题 控制器 if($request->hasFile('files')){ $store_file = []; $exif = exif_read_data($request->file('files')); if(!empty($exi

当我将图像上传到数据库时,Laravel会旋转它们,所以我发现 ,然后在实现它之后,我得到这个错误
exif\u read\u data()期望参数1是一个有效的路径,数组给定
。我怎样才能解决这个问题

控制器

 if($request->hasFile('files')){

        $store_file = [];

        $exif = exif_read_data($request->file('files'));
        if(!empty($exif['Orientation'])) {
            switch($exif['Orientation']) {
                case 8:
                    $image = imagerotate($image,90,0);
                    break;
                case 3:
                    $image = imagerotate($image,180,0);
                    break;
                case 6:
                    $image = imagerotate($image,-90,0);
                    break;
            }
        }


       // $files = $request->file('files');
        foreach ($exif as $file) {
            $path = $file->storeAs('public/photos');

            $store_file[] = [

                'product_id' => $product->id,
                'filename' =>  $path
            ];
        }

由于错误mentiened
exif\u read\u data()期望参数1是有效路径,因此给定数组

您必须提供从存储器到
exif\u read\u data()
函数的映像路径,这意味着您需要循环通过$request->file('files')并通过

$path = $file->store('public/photos');
然后

修复

if($request->hasFile('files')){

    $store_file = [];

    foreach ($request->file('files') as $file) {

        $fileName = uniqid() . time() . '.' . $file->getClientOriginalExtension();

        $file->storeAs('public/photos', $fileName);

        $filePath = $file->getPathName();

        $exif = @exif_read_data($filePath);

        if(isset($exif['Orientation'])) {

            switch($exif['Orientation']) {
                case 8:
                    $deg = 90;
                    break;
                case 3:
                    $deg = 180;
                    break;
                case 6:
                    $deg = -90;
                    break;
            }

            if (isset($deg)) {

                $fullQualifiedFilePath = storage_path('app/public/photos/' . $fileName);

                if ($file->getClientOriginalExtension() == "png") {
                    $img_new = imagecreatefrompng($fullQualifiedFilePath);
                    $img_new = imagerotate($img_new, $deg, 0);

                    imagepng($img_new, $fullQualifiedFilePath);
                } else {
                    $img_new = imagecreatefromjpeg($fullQualifiedFilePath);
                    $img_new = imagerotate($img_new, $deg, 0);

                    imagejpeg($img_new, $fullQualifiedFilePath, 80);
                }
           }
       }

        $store_file[] = [

            'product_id' => $product->id,
            'filename' =>  'public/photos/' . $fileName
        ];
    }

    ProductsPhoto::insert($store_file);
}

参考

那么我把这个
exif\u read\u data()
代码放在哪里,因为我很困惑@Foued MOUSSII仍然获得
期望参数是有效路径
您可以检查编辑的问题@Foued MOUSSII获得
未定义变量:exif“
@Foued MOUSSII在资源上调用成员函数storeAs()时遇到另一个错误,
@Foued MOUSSITry对此行进行注释
$image->storeAs('public/photos',$fileName”)并重试
if($request->hasFile('files')){

    $store_file = [];

    foreach ($request->file('files') as $file) {

        $fileName = uniqid() . time() . '.' . $file->getClientOriginalExtension();

        $file->storeAs('public/photos', $fileName);

        $filePath = $file->getPathName();

        $exif = @exif_read_data($filePath);

        if(isset($exif['Orientation'])) {

            switch($exif['Orientation']) {
                case 8:
                    $deg = 90;
                    break;
                case 3:
                    $deg = 180;
                    break;
                case 6:
                    $deg = -90;
                    break;
            }

            if (isset($deg)) {

                $fullQualifiedFilePath = storage_path('app/public/photos/' . $fileName);

                if ($file->getClientOriginalExtension() == "png") {
                    $img_new = imagecreatefrompng($fullQualifiedFilePath);
                    $img_new = imagerotate($img_new, $deg, 0);

                    imagepng($img_new, $fullQualifiedFilePath);
                } else {
                    $img_new = imagecreatefromjpeg($fullQualifiedFilePath);
                    $img_new = imagerotate($img_new, $deg, 0);

                    imagejpeg($img_new, $fullQualifiedFilePath, 80);
                }
           }
       }

        $store_file[] = [

            'product_id' => $product->id,
            'filename' =>  'public/photos/' . $fileName
        ];
    }

    ProductsPhoto::insert($store_file);
}