【问题标题】:Class 'TusPhp\Tus\Client' not found找不到类“TusPhp\Tus\Client”
【发布时间】:2019-08-30 22:12:23
【问题描述】:

当我上传文件时,我在 PHP 中使用 vimeo-api 库,它给了我这个错误。我不知道为什么会出现这个错误,请看看这个,让我知道为什么会出现这个错误 错误:找不到类 'TusPhp\Tus\Client' 这是我的代码

<?php
use Vimeo\Vimeo;
use Vimeo\Exceptions\VimeoUploadException;
/**
 *   Copyright 2013 Vimeo
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
$config = require(__DIR__ . '/init.php');
if (empty($config['access_token'])) {
    throw new Exception(
        'You can not upload a file without an access token. You can find this token on your app page, or generate ' .
        'one using `auth.php`.'
    );
}
// Instantiate the library with your client id, secret and access token (pulled from dev site)
$lib = new Vimeo($config['client_id'], $config['client_secret'], $config['access_token']);
// Create a variable with a hard coded path to your file system
$file_name = "C:\Users\BASIT\Downloads\SampleVideo_1280x720_1mb.mp4";
echo 'Uploading: ' . $file_name . "\n";
try {
    // Upload the file and include the video title and description.
    $uri = $lib->upload($file_name, array(
        'name' => 'Vimeo API SDK test upload',
        'description' => "This video was uploaded through the Vimeo API's PHP SDK."
    ));
    // Get the metadata response from the upload and log out the Vimeo.com url
    $video_data = $lib->request($uri . '?fields=link');
    echo '"' . $file_name . ' has been uploaded to ' . $video_data['body']['link'] . "\n";
    // Make an API call to edit the title and description of the video.
    $lib->request($uri, array(
        'name' => 'Vimeo API SDK test edit',
        'description' => "This video was edited through the Vimeo API's PHP SDK.",
    ), 'PATCH');
    echo 'The title and description for ' . $uri . ' has been edited.' . "\n";
    // Make an API call to see if the video is finished transcoding.
    $video_data = $lib->request($uri . '?fields=transcode.status');
    echo 'The transcode status for ' . $uri . ' is: ' . $video_data['body']['transcode']['status'] . "\n";
} catch (VimeoUploadException $e) {
    // We may have had an error. We can't resolve it here necessarily, so report it to the user.
    echo 'Error uploading ' . $file_name . "\n";
    echo 'Server reported: ' . $e->getMessage() . "\n";
} catch (VimeoRequestException $e) {
    echo 'There was an error making the request.' . "\n";
    echo 'Server reported: ' . $e->getMessage() . "\n";
}

【问题讨论】:

  • 你安装了吗?你用作曲家吗? TusPhp 是该库的依赖项(如果我正在查看正确的 github 页面)。
  • @Jonnix 没有用 composer 安装它我只是从 git 下载 zip
  • 错误在这一行 --- $client = new \TusPhp\Tus\Client($base_url);
  • 如果你只是从 git 安装它,很可能你没有依赖关系,因此你得到的错误。您需要下载每个依赖项并将它们放在库/自动加载器可以找到的位置。您可以在库目录中的 composer.json 中找到依赖项。或者你可以使用composer为自己节省很多精力。
  • 我还在 cmd 中添加了 update composer 命令,但是 TusPhp 文件没有下载,请告诉我如何下载它。

标签: php vimeo-api


【解决方案1】:

嗨,如果您使用像 codeigniter 这样的框架 php,那么您还可以在自动加载文件和路径中声明 $file_name = "C:\Users\BASIT\Downloads\SampleVideo_1280x720_1mb.mp4";不工作它只是应用单引号然后它工作正常

【讨论】:

    猜你喜欢
    • 2021-04-11
    • 1970-01-01
    • 2015-09-22
    • 2017-06-14
    • 1970-01-01
    • 2020-02-10
    • 2017-12-24
    • 1970-01-01
    • 2019-08-29
    相关资源
    最近更新 更多