user2323920
user2323920

Reputation: 19

Uploading with Vimeo API 1.2.3 in PHP Script

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

Upvotes: 0

Views: 1473

Answers (1)

user2323920
user2323920

Reputation: 19

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>

Upvotes: 1

Related Questions