2015-11-10 47 views
1

首先,讓我說,我已經有一段艱難的時間來提問,這些問題是以Stack Overflow社區感到滿意的方式制定的。所以,我希望這個問題是可以接受的 - 我只是尋找一些我在任何地方都找不到的幫助。謝謝!當文件存在時PHP?

我正在製作一個應用程序,允許用戶通過Web表單自定義視頻,點擊提交,JSON攝入視頻軟件,該軟件會自動在我們的服務器上呈現項目,然後通過FTP自動上傳到http://www.example.com/video-renders/

假設用戶在表單提交時指定的文件名是video.mp4

當該用戶提交渲染/上傳項目時,是否可以觸發該PHP腳本'012'觀看video-renders目錄中的filename = video.mp4並執行腳本將視頻上傳到Wistia?

這裏是我的PHP,成功地上傳文件(URL)來Wistia:

<?php 

$api_request_url = 'https://upload.wistia.com'; 
$method_name = 'POST'; 

$api_request_parameters = array(
    'api_password' => '<<my_api_password>>', 
    'url' => 'http://www.example.com/video-renders/'.$_POST['video-name'], 
    'project_id' => $_POST['user-project-id'] 
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 

if ($method_name == 'DELETE') 
{ 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($api_request_parameters)); 
} 

if ($method_name == 'GET') 
{ 
    $api_request_url .= '?' . http_build_query($api_request_parameters); 
} 

if ($method_name == 'POST') 
{ 
    curl_setopt($ch, CURLOPT_POST, TRUE); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($api_request_parameters)); 
} 

if ($method_name == 'PUT') 
{ 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($api_request_parameters)); 
} 

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); 
curl_setopt($ch, CURLOPT_URL, $api_request_url); 
curl_setopt($ch, CURLOPT_HEADER, TRUE); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

$api_response = curl_exec($ch); 
$api_response_info = curl_getinfo($ch); 
curl_close($ch); 

$api_response_header = trim(substr($api_response, 0, $api_response_info['header_size'])); 
$api_response_body = substr($api_response, $api_response_info['header_size']); 

// Response HTTP Status Code 
echo $api_response_info['http_code']; 

// Response Header 
echo $api_response_header; 

// Response Body 
echo $api_response_body; 

?> 

回答

0
  1. 使這個PHP腳本作爲一個長期運行的進程和STAT文件定期

OR

  1. 在上傳腳本中,上傳完成後,創建一個作業並將其傳遞給消息隊列,可以使用此PHP腳本作爲工人,推薦。
+0

謝謝,但#2不可用,因爲我的渲染軟件(Adobe Media Encoder)具有內置的FTP功能。如何循環PHP腳本直到「成功」? – user1661677