2015-06-03 86 views
0

這裏是我的代碼:上傳與Vimeo的API 1.2.3 PHP腳本

<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 
} 
?> 

問題:

當我提交上傳沒有錯誤的產生沒有任何一個文件被上傳它,它炸燬時調用上傳方法。我在這裏做錯了什麼?我不希望任何用戶與回調交互只是簡單的直接上傳沒有問題。

感謝您給我的任何幫助。 拉里

+0

基於錯誤,這可能是值得探討http://stackoverflow.com/a/9595886/4941437 – lid

+0

任何機會,你的腳本是隱藏的錯誤?嘗試添加以下內容:'error_reporting(E_ALL); ini_set('display_errors','1');' – Dashron

回答

0
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>