Thinkphp+七牛找不到類的緣由(Class 'Qiniu\Auth' not found)

thinkphp+七牛作圖片等文件上傳發現結果報Class 'Qiniu\Auth' not found 這樣的錯誤。 也就是沒有找到七牛的驗證類,我提供解決的方案以下。php

輸入圖片說明

這裏是tp入口文件,你須要加裝這麼一個文件,通常你下載七牛的sdk都會帶這個文件,內部代碼以下:thinkphp

<?php

function classLoader($class)
{
    $path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
    $file = __DIR__ . '/Qiniu/' . $path . '.php';

    if (file_exists($file)) {
        require_once $file;
    }
}
spl_autoload_register('classLoader');

require_once  __DIR__ . '/Qiniu/Qiniu/functions.php';

這樣會尋找你的七牛文件夾去,而後自動加載七牛的類。ui

這樣的話,你就只要引入七牛的類就能夠了spa

namespace Yun\Controller;
use Think\Controller;
use Think\Exception;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
class MController extends Controller{
    
}

這樣就不會報找不到到類的錯誤了!code

相關文章
相關標籤/搜索