gpt4 book ai didi

php - 上传大视频

转载 作者:行者123 更新时间:2023-12-04 08:34:40 28 4
gpt4 key购买 nike

我正在将图像/pdf 上传到 S3Uploads 并将视频上传到 JwPlayer。它工作正常。现在我需要上传大视频,它可以是 10,20... GB。
问题是客户端不想更改 php.ini 或创建 .user.ini 或更改 .htaccess 文件以增加上传文件大小和帖子大小。
如何上传大视频。找到解决方案https://github.com/ankitpokhrel/tus-php它还支持前端的 UPPY,但我不知道如何将它实现到 jwplatform 上传。请帮忙。
我正在使用的前端 - https://uppy.io/docs/xhr-upload/

<link href="<?=base_url(); ?>assets/uppy.min.css" rel="stylesheet">
<script src="<?=base_url(); ?>assets/uppy.min.js"></script>
<script>
var uppy = Uppy.Core()
.use(Uppy.Dashboard, {
inline: true,
formData:true,
target: '#drag-drop-area'
})
.use(Uppy.XHRUpload, {endpoint: uploadUrl', method:'post'}) //you can put upload URL here, where you want to upload images
.uppy.on('complete', (result) => {
console.log('Upload complete! We’ve uploaded these files:', result.successful)
});
</script>
后端 - https://github.com/jwplayer/jwplatform-php (用于视频上传)
    $cpt = count($_FILES['files']['name']);
$thumb = NULL;
$video_key = NULL;
$uploadedImages = [];
for($i=0; $i<$cpt; $i++)
{
$mime = $_FILES['files']['type'][$i];
if(strstr($mime, "video/")){
$filetype = "video";
}else if(strstr($mime, "image/")){
$filetype = "img";
}else if(strstr($mime, "/pdf")){
$filetype = "pdf";
}else{
$filetype = "";
}
if(!empty($_FILES['files']['name'][$i]) && !empty($filetype)){
$path = "upload/media/";
try {
if ($filetype=='video'){
$video_path = $_FILES['files']['tmp_name'][$i];
if ($video_path) {
$params = array();
$params['title'] = $_FILES['files']['name'][$i];
$params['description'] = 'Not available';


$jwplatform_api = new Jwplayer\JwplatformAPI('aaaasdf', 'asdfasdfasdfasdf');

$create_response = json_encode($jwplatform_api->call('/videos/create', $params));

$decoded = json_decode(trim($create_response), TRUE);
$upload_link = $decoded['link'];
$upload_response = $jwplatform_api->upload($video_path, $upload_link);

$video_key = $upload_response['media']['key'];
$file_url = $video_path;
}
}
else{
$filename = time()."_".$_FILES['files']['name'][$i];
$file_url = s3UploadMultiple($_FILES['files']['tmp_name'][$i],$path,$filename);

if (!empty($file_url) && $filetype == "img"){
$thumb = thumbnail($account_id,$file_url,150,150,"/media/thumbnails/");
}else{
$thumb = $file_url;
}
}
$new = new Medialib;
$new->account_id = $account_id;
$new->file_url = $file_url;
$new->file_thumb = $thumb;
$new->file_type = $filetype;
$new->video_key = $video_key;
$new->title = $_FILES['files']['name'][$i];

$new->save();

$new = Medialib::find('last',array('conditions'=>array('account_id'=>$account_id,'file_url'=>$file_url)));

array_push($uploadedImages,(object)["id"=>$new->id,"src"=>$new->file_url, "thumb" => $thumb]);
} catch (Exception $e) {
echo $e;
}

}
}
echo json_encode($uploadedImages);

}

最佳答案

不幸的是,目前不支持 tus 协议(protocol)。
上传大文件的最佳方法是将其上传到中间位置(如 S3)并通过设置 download_url 将文件导入 jwplatform到文件的链接。 example folder of jwplatform-php 中有一个如何做到这一点的例子。 .此方法支持最大 25 GB 的文件。
如果这不可能,您的下一个最佳选择是使用可恢复上传。 developer docs 中有关于如何执行此操作的指南.还有一个如何做到这一点的例子in Python (这应该很容易移植)。

关于php - 上传大视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64853447/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com