没有不值得去解决的问题,也没有不值得去学习的技术!

Error in Laravel 5.4: Call to undefined function App\\App\\Services\\exif_read_data()

在 Laravel 5.4 中报错:Call to undefined function App\\App\\Services\\exif_read_data()。

1. Error in Laravel 5.4: Call to undefined function App\\App\\Services\\exif_read_data(). See Figure 1.

Error in Laravel 5.4: Call to undefined function App\\App\\Services\\exif_read_data().
Figure 1
JSON

{
  "code": 10000,
  "message": "Call to undefined function App\\App\\Services\\exif_read_data()",
  "trace": [
    {
      "file": "E:\\wwwroot\\msi_main\\app\\App\\Services\\StorageService.php",
      "line": 66,
      "function": "image_fix_orientation",
      "class": "App\\App\\Services\\StorageService",
      "type": "->",
      "args": [
        "E:\\phpuploadtmp\\php8753.tmp"
      ]
    },
    {
      "file": "E:\\wwwroot\\msi_main\\app\\Http\\Controllers\\Web\\Prize\\PrizeController.php",
      "line": 458,
      "function": "storeAsTmpImage",
      "class": "App\\App\\Services\\StorageService",
      "type": "->",
      "args": [
        {},
        {
          "ext": "jpg"
        }
      ]
    },
    {
      "function": "upload",
      "class": "App\\Http\\Controllers\\Web\\Prize\\PrizeController",
      "type": "->",
      "args": [
        {
          "attributes": {},
          "request": {},
          "query": {},
          "server": {},
          "files": {},
          "cookies": {},
          "headers": {}
        },
        {}
      ]
    },
    {
      "file": "E:\\wwwroot\\msi_main\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Controller.php",
      "line": 55,
      "function": "call_user_func_array",
      "args": [
        [
          {},
          "upload"
        ],
        [
          {
            "attributes": {},
            "request": {},
            "query": {},
            "server": {},
            "files": {},
            "cookies": {},
            "headers": {}
          },
          {}
        ]
      ]
    },
    {
      "file": "E:\\wwwroot\\msi_main\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\ControllerDispatcher.php",
      "line": 44,
      "function": "callAction",
      "class": "Illuminate\\Routing\\Controller",
      "type": "->",
      "args": [
        "upload",
        [
          {
            "attributes": {},
            "request": {},
            "query": {},
            "server": {},
            "files": {},
            "cookies": {},
            "headers": {}
          },
          {}
        ]
      ]
    },
    {
      "file": "E:\\wwwroot\\msi_main\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php",
      "line": 203,
      "function": "dispatch",
      "class": "Illuminate\\Routing\\ControllerDispatcher",
      "type": "->",
      "args": [
        {
          "uri": "web/prize/upload",
          "methods": [
            "POST"
          ],
          "action": {
            "middleware": "web",
            "uses": "App\\Http\\Controllers\\Web\\Prize\\PrizeController@upload",
            "controller": "App\\Http\\Controllers\\Web\\Prize\\PrizeController@upload",
            "namespace": "App\\Http\\Controllers",
            "prefix": null,
            "where": []
          },
          "controller": {},
          "defaults": [],
          "wheres": [],
          "parameters": [],
          "parameterNames": [],
          "computedMiddleware": [
            "web"
          ],
          "compiled": {}
        },
        {},
        "upload"
      ]
    },
    {
      "file": "E:\\wwwroot\\msi_main\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Route.php",
      "line": 160,
      "function": "runController",
      "class": "Illuminate\\Routing\\Route",
      "type": "->",
      "args": []
    },
    {
      "file": "E:\\wwwroot\\msi_main\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Router.php",
      "line": 572,
      "function": "run",
      "class": "Illuminate\\Routing\\Route",
      "type": "->",
      "args": []
    },
    {
      "file": "E:\\wwwroot\\msi_main\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\Pipeline.php",
      "line": 30,
      "function": "Illuminate\\Routing\\{closure}",
      "class": "Illuminate\\Routing\\Router",
      "type": "->",
      "args": [
        {
          "attributes": {},
          "request": {},
          "query": {},
          "server": {},
          "files": {},
          "cookies": {},
          "headers": {}
        }
      ]
    },
    {
      "file": "E:\\wwwroot\\msi_main\\app\\Http\\Middleware\\ConsoleCMCAuthenticate.php",
      "line": 73,
      "function": "Illuminate\\Routing\\{closure}",
      "class": "Illuminate\\Routing\\Pipeline",
      "type": "->",
      "args": [
        {
          "attributes": {},
          "request": {},
          "query": {},
          "server": {},
          "files": {},
          "cookies": {},
          "headers": {}
        }
      ]
    }
  ]
}

2. exif_read_data — Reads the EXIF headers from an image file. It is an Exif function that depends on the Exif extension. Checking phpinfo, the Exif extension is not installed. See Figure 2.

exif_read_data — Reads the EXIF headers from an image file. It is an Exif function that depends on the Exif extension. Checking phpinfo, the Exif extension is not installed.
Figure 2

3. The local environment is Windows 10. Checking the extensions directory: C:\php-7.4.6\ext, the file php_exif.dll exists. See Figure 3.

The local environment is Windows 10. Checking the extensions directory: C:\php-7.4.6\ext, the file php_exif.dll exists.
Figure 3

4. Edit the php.ini file. Remove the ; from ;extension=exif.
Before modification:

INI

;extension=exif      ; Must be after mbstring as it depends on it

After modification:

INI

extension=exif      ; Must be after mbstring as it depends on it

5. Check phpinfo. The Exif extension is now installed. See Figure 4.

Check phpinfo. The Exif extension is now installed.
Figure 4

6. Upload the image again; no error occurs. See Figure 5.

Upload the image again; no error occurs.
Figure 5

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系