dpgjci27392 2015-06-03 16:12
浏览 26

使用PHP脚本中的Vimeo API 1.2.3上传

Here is my code:

<html>
<body>
<form action="upload_new.php" method="post" enctype="multipart/form-data">
<h2>Vimeo Uploader</h2>
<label for="file">Filename:</label>
<input type="file" multiple name="file[]" id="file"><br><br/>
<input class="upload" type="submit" name="upload" value="Upload"><br/>
</form>
</body>
</html>
<?php
use Vimeo\Vimeo;
use Vimeo\Exceptions;
use Vimeo\Exceptions\VimeoUploadException;
require_once 'Vimeo/Vimeo.php';
require_once 'Vimeo/Exceptions/ExceptionInterface.php';
require_once 'Vimeo/Exceptions/VimeoRequestException.php';
require_once 'Vimeo/Exceptions/VimeoUploadException.php';
$lib = new Vimeo('client_id', 'client_secret');
for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
$fileName = $_FILES["file"]["name"][$i];
$fileType = $_FILES["file"]["type"][$i];
$fileSize = $_FILES["file"]["size"][$i];
$fileTempName = $_FILES["file"]["tmp_name"][$i];
echo $fileTempName;
$uri = $lib->upload($fileTempName); //BLOWS HERE WITH NO MESSAGE
echo 'uri = ' . $uri; //THIS NEVER EXECUTES
}
?>

Problem:

When I submit a file for upload no errors are generated nothing was uploaded it it blows up when calling the upload method. What am I doing wrong here? I don't want any user interaction with callbacks just a plain straight upload no questions asked.

Thanks for any help you can give me. Larry

  • 写回答

1条回答 默认 最新

  • duanpin2009 2015-08-20 13:35
    关注
    BATCH UPLOADING VIDEOS TO VIMEO
    1. Create a Vimeo App
    a. Logon to Vimeo and proceed to developer.vimeo.com/api.
    b. From the Vimeo API Page click the link "register your app" in the API column.
    c. Click the "Create a new app" button and fill out the top two fields "App Name" (i.e. Uploader) and "App Description" (Description should state the purpose of your new app), check "I Agree" and then "Create App"
    d. Wait for approval from Vimeo in an email.
    e. Once approved return to developer.vimeo.com/api and click on "My Apps".
    f. Click on you new app which should be listed.
    g. Click "Edit Settings" make any changes to the settings if needed when done click save.
    h. Fill check the appropriate check boxes at the bottom of the page under Generate an Access Token/Scopes (i.e. public) and then click the "Generate Token" button.
    i. From the "My API Apps/your_app_name" page click "Authentication" and copy the "Access Token", "Client Identifier" and "Client Secrets" fields to a secure text document temporarilly for future reference.  These identifiers should never expire unless you recreate new ones.
    
    2. Create a folder on your server where you html, php and php.ini files will live.
    a. Copy an existing php.ini and add or modify the entries listed in the php ini settings below.
    
    PHP.INI Settings:
    
    [PHP]
    
    ; Maximum size of POST data that PHP will accept.
    ; Its value may be 0 to disable the limit. It is ignored if POST data reading
    ; is disabled through enable_post_data_reading.
    post_max_size = 71690M
    
    ; Maximum allowed size for uploaded files.
    ;post_max_size should be > upload_max_filesize see also max_execution_time
    upload_max_filesize = 71680M
    
    ; Maximum number of files that can be uploaded via a single request
    max_file_uploads = 60
    
    ; Maximum execution time of each script, in seconds
    ; Note: This directive is hardcoded to 0 for the CLI SAPI
    ;max_execution_time = 5400
    max_execution_time = 600000
    
    ; Maximum amount of time each script may spend parsing request data. It's a good
    ; idea to limit this time on productions servers in order to eliminate unexpectedly
    ; long running scripts.
    ; Note: This directive is hardcoded to -1 for the CLI SAPI
    ; Default Value: -1 (Unlimited)
    ; Development Value: 60 (60 seconds)
    ; Production Value: 60 (60 seconds)
    max_input_time = 60
    
    ; Maximum amount of memory a script may consume (default = 128MB)
    memory_limit = 2048M
    
    3. Copy this PHP file into your folder with the name: upload_new.php 
    
    <?php
    // NOTE: This script does not work when called from AJAX
    //       because $_FILES is always empty. 
    use Vimeo\Vimeo;
    use Vimeo\Exceptions;
    use Vimeo\Exceptions\VimeoUploadException;
    require_once 'Vimeo/Vimeo.php';
    require_once 'Vimeo/Exceptions/ExceptionInterface.php';
    require_once 'Vimeo/Exceptions/VimeoRequestException.php';
    require_once 'Vimeo/Exceptions/VimeoUploadException.php';
    require_once 'upload_exception.php';
    $client_id = 'your client id from step 1. i above';
    $client_secret = 'your client secret from step 1. i above';
    $accessToken = 'your access token from step 1. i above';
    $uri = '';
    $i = 0;
    ob_end_clean();
    header("Connection: close");
    ignore_user_abort(); // optional
    ob_start();
    $size = ob_get_length();
    header("Content-Length: $size");
    ob_end_flush();
    flush();
    $startTime = date('H:i:s');
    echo 'Start time: ' . $startTime . '<br/>';
    $lib = new Vimeo($client_id, $client_secret, $accessToken);
    for ($i = 0; $i < count($_FILES['file']['name'])-1; $i++) {
    if ($_FILES['file']['error'][$i] === UPLOAD_ERR_OK) { 
    $fileName = $_FILES["file"]["name"][$i];
    $fileType = $_FILES["file"]["type"][$i];
    $fileSize = $_FILES["file"]["size"][$i];
    $fileTempName = $_FILES["file"]["tmp_name"][$i];
    $fileError = $_FILES["file"]["error"][$i];
    try {
    $uri = $lib->upload($fileTempName);
    $lib->request($uri, array('name' => $fileName), 'PATCH');
    $lib->request($uri, array('description' => 'Please enter a description for ' . $fileName), 'PATCH');
    $lib->request($uri, 'me/channels/944590/videos/', 'PUT');
    }
    catch (\Vimeo\Exceptions\VimeoRequestException $exception) {
    }
    //return vimeo ids
    echo 'Original filename: "' . $fileName . '"; vimeo id: "' . $uri . '"' . '<br/>';
    }
    else { 
    echo '<br/>' . 'Upload Error: ' . var_dump($_FILES["file"]["error"]) . '<br/>';
    throw new UploadException($_FILES['file']['error'][$i]); 
    } 
    }
    $endTime = date('H:i:s');
    echo 'End time: ' . $endTime . '<br/>';
    ?>
    
    
    4. Copy this html file into your folder with the name of your choice
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Vimeo Batch Uploader</title>
    </head>
    <body>
    <form action="upload_new.php" method="post" enctype="multipart/form-data">
    <h2>AETV Vimeo Uploader</h2>
    <label for="file">Filename:</label>
    <input type="file" multiple name="file[]" id="file"><br><br/>
    <input class="upload" type="submit" name="upload" value="Upload"><br/>
    </form>
    </body>
    </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图