John Davidson

Is 'base64_encode' working good with videos in php?

0 comments
Message:


I have a privet forms to give courses online that users can register and watching the video course Online after payment , And I need to produce the video without showing the original URL source by using this function :


// Get video view tag
function GetVideoViewTag(&$fld, $val, $tooltip = false)
{
global $Page;
if (!EmptyString($val)) {
$val = $fld->htmlDecode($val);
if ($fld->DataType == DATATYPE_BLOB) {
$wrknames = [$val];
$wrkfiles = [$val];
} elseif ($fld->UploadMultiple) {
$wrknames = explode(Config("MULTIPLE_UPLOAD_SEPARATOR"), $val);
$wrkfiles = explode(Config("MULTIPLE_UPLOAD_SEPARATOR"), $fld->htmlDecode($fld->Upload->DbValue));
} else {
$wrknames = [$val];
$wrkfiles = [$fld->htmlDecode($fld->Upload->DbValue)];
}
$multiple = (count($wrkfiles) > 1);
$href = $tooltip ? "" : $fld->HrefValue;
$isLazy = $tooltip ? false : IsLazy();
$tags = "";
$wrkcnt = 0;
foreach ($wrkfiles as $wrkfile) {
$tag = "";
if (
$Page && ($Page->TableType == "REPORT" &&
($Page->isExport("excel") && Config("USE_PHPEXCEL") ||
$Page->isExport("word") && Config("USE_PHPWORD")) ||
$Page->TableType != "REPORT" && ($Page->CustomExport == "pdf" || $Page->CustomExport == "email"))
) {
$fn = GetFileTempImage($fld, $wrkfile);
} else {
$fn = GetFileUploadUrl($fld, $wrkfile, $fld->Resize);
}
$fi = base64_encode(file_get_contents('http://localhost/onlincu/files/'.$wrkfile));
if ($href == "" && !$fld->UseColorbox) {
if ($fn != "") {
if ($isLazy) {
$tag = '<center><video style="width: 100%; height: 380px;" autoplay controls controlsList="nodownload"><source src="data:video/mp4;base64,'.$fi.'" type="video/mp4" data-src="' . $fn . '"' . $fld->viewAttributes() . '></video></center>';
} else {
$tag = '<center><video style="width: 100%; height: 380px;" autoplay controls controlsList="nodownload"><source src="data:video/mp4;base64,'.$fi.'" type="video/mp4" data-src="' . $fn . '"' . $fld->viewAttributes() . '></video></center>';
}
}
} else {
if ($fld->UploadMultiple && ContainsString($href, '%u')) {
$fld->HrefValue = str_replace('%u', GetFileUploadUrl($fld, $wrkfile), $href);
}
if ($fn != "") {
if ($isLazy) {
$tag = '<center><video style="width: 100%; height: 380px;" autoplay controls controlsList="nodownload"><source src="data:video/mp4;base64,'.$fi.'" type="video/mp4" data-src="' . $fn . '"' . $fld->viewAttributes() . '></video></center>';
} else {
$tag = '<center><video style="width: 100%; height: 380px;" autoplay controls controlsList="nodownload"><source src="data:video/mp4;base64,'.$fi.'" type="video/mp4" data-src="' . $fn . '"' . $fld->viewAttributes() . '></video></center>';
}
}
}
if ($tag != "") {
if ($multiple) {
$tags .= '<div class="p-1">' . $tag . '</div>';
} else {
$tags .= $tag;
}
}
$wrkcnt += 1;
}
if ($multiple && $tags != "") {
$tags = '<div class="d-flex flex-row">' . $tags . '</div>';
}
return $tags;
}
return "";
}

Now my function working Good even better until now , But I have read that using 'base64_encode' for videos maybe damage the original video , Well if that true What the better solution for this case ?


I appreciate your help .



My Answer:
there anything specific you would like to know or discuss?

Rate this post

5 of 5 based on 3273 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us