本文整理汇总了PHP中kFile::fileSize方法的典型用法代码示例。如果您正苦于以下问题:PHP kFile::fileSize方法的具体用法?PHP kFile::fileSize怎么用?PHP kFile::fileSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kFile
的用法示例。
在下文中一共展示了kFile::fileSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadFileToToken
/**
* Upload a file to the current upload token
* @param file $fileData
* @param bool $resume
* @param bool $finalChunk
* @param int $resumeAt
*/
public function uploadFileToToken($fileData, $resume = false, $finalChunk = true, $resumeAt = -1)
{
$allowedStatuses = array(UploadToken::UPLOAD_TOKEN_PENDING, UploadToken::UPLOAD_TOKEN_PARTIAL_UPLOAD);
if (!in_array($this->_uploadToken->getStatus(), $allowedStatuses, true)) {
throw new kUploadTokenException("Invalid upload token status", kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS);
}
$this->updateFileName($fileData);
try {
$this->checkIfFileIsValid($fileData);
} catch (kUploadTokenException $ex) {
if (!$resume && $finalChunk) {
kFlowHelper::handleUploadFailed($this->_uploadToken);
}
$this->tryMoveToErrors($fileData);
throw $ex;
}
if ($resume) {
$this->handleResume($fileData, $resumeAt);
} else {
$this->handleMoveFile($fileData);
}
$fileSize = kFile::fileSize($this->_uploadToken->getUploadTempPath());
if ($finalChunk) {
$this->_uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_FULL_UPLOAD);
} else {
$this->_uploadToken->setStatus(UploadToken::UPLOAD_TOKEN_PARTIAL_UPLOAD);
}
$this->_uploadToken->setUploadedFileSize($fileSize);
$this->_uploadToken->setDc(kDataCenterMgr::getCurrentDcId());
$this->_uploadToken->save();
$this->addTrackEntry();
}
示例2: crop
public function crop($quality, $cropType, $width = 0, $height = 0, $cropX = 0, $cropY = 0, $cropWidth = 0, $cropHeight = 0, $scaleWidth = 1, $scaleHeight = 1, $bgcolor = 0xffffff, $density = 0, $forceRotation = null, $strip = false)
{
if (is_null($quality)) {
$quality = 100;
}
if (is_null($cropType)) {
$cropType = 1;
}
if (is_null($width)) {
$width = 0;
}
if (is_null($height)) {
$height = 0;
}
if (is_null($cropX)) {
$cropX = 0;
}
if (is_null($cropY)) {
$cropY = 0;
}
if (is_null($cropWidth)) {
$cropWidth = 0;
}
if (is_null($cropHeight)) {
$cropHeight = 0;
}
if (is_null($scaleWidth)) {
$scaleWidth = 1;
}
if (is_null($scaleHeight)) {
$scaleHeight = 1;
}
if (is_null($bgcolor)) {
$bgcolor = 0;
}
$cmd = $this->getCommand($quality, $cropType, $width, $height, $cropX, $cropY, $cropWidth, $cropHeight, $scaleWidth, $scaleHeight, $bgcolor, $density, $forceRotation, $strip);
if ($cmd) {
KalturaLog::info("Executing: {$cmd}");
$returnValue = null;
$output = system($cmd, $returnValue);
KalturaLog::debug("Returned value: '{$returnValue}'");
if ($returnValue) {
return false;
}
// Support animated gifs - KImageMagick generates multiple images with a postfix of '-<frame num>'
if (!kFile::fileSize($this->targetPath)) {
$targetFiledir = pathinfo($this->targetPath, PATHINFO_DIRNAME);
$targetFilename = pathinfo($this->targetPath, PATHINFO_FILENAME);
$targetFileext = pathinfo($this->targetPath, PATHINFO_EXTENSION);
$firstFrameTargetFile = "{$targetFiledir}/{$targetFilename}-0.{$targetFileext}";
if (kFile::fileSize($firstFrameTargetFile)) {
kFile::moveFile($firstFrameTargetFile, $this->targetPath);
}
}
return true;
}
KalturaLog::info("No conversion required, copying source[{$this->srcPath}] to target[{$this->targetPath}]");
return copy($this->srcPath, $this->targetPath);
}
示例3: moveFile
/**
* @param KalturaBatchJob $job
* @param KalturaConcatJobData $data
* @param string $localTempFilePath
* @param string $sharedTempFilePath
* @return KalturaBatchJob
*/
protected function moveFile(KalturaBatchJob $job, KalturaConvertLiveSegmentJobData $data, $localTempFilePath, $sharedTempFilePath)
{
$this->updateJob($job, "Moving file from [{$localTempFilePath}] to [{$sharedTempFilePath}]", KalturaBatchJobStatus::MOVEFILE);
kFile::moveFile($localTempFilePath, $sharedTempFilePath, true);
clearstatcache();
$fileSize = kFile::fileSize($sharedTempFilePath);
$this->setFilePermissions($sharedTempFilePath);
if (!$this->checkFileExists($sharedTempFilePath, $fileSize)) {
return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, 'File not moved correctly', KalturaBatchJobStatus::RETRY);
}
$data->destFilePath = $sharedTempFilePath;
return $this->closeJob($job, null, null, 'Succesfully moved file', KalturaBatchJobStatus::FINISHED, $data);
}
示例4: moveFile
protected function moveFile(KalturaBatchJob $job, KalturaLiveReportExportJobData $data, $partnerId)
{
$fileName = basename($data->outputPath);
$sharedLocation = self::$taskConfig->params->sharedPath . DIRECTORY_SEPARATOR . $partnerId . "_" . $fileName;
$fileSize = kFile::fileSize($data->outputPath);
rename($data->outputPath, $sharedLocation);
$data->outputPath = $sharedLocation;
$this->setFilePermissions($sharedLocation);
if (!$this->checkFileExists($sharedLocation, $fileSize)) {
return $this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, 'Failed to move report file', KalturaBatchJobStatus::RETRY);
}
return $this->closeJob($job, null, null, 'CSV created successfully', KalturaBatchJobStatus::FINISHED, $data);
}
示例5: doPutFile
protected function doPutFile($remote_file, $local_file, $ftp_mode, $http_field_name = null, $http_file_name = null)
{
list($bucket, $remote_file) = explode("/", ltrim($remote_file, "/"), 2);
KalturaLog::debug("remote_file: " . $remote_file);
$res = $this->s3->putObjectFile($local_file, $bucket, $remote_file);
if ($res) {
$info = $this->s3->getObjectInfo($bucket, $remote_file);
if ($info && $info['size'] == kFile::fileSize($local_file)) {
KalturaLog::debug("File uploaded to Amazon, info: " . print_r($info, true));
return true;
} else {
KalturaLog::debug("error uploading file " . $local_file . " s3 info " . print_r($info, true));
return false;
}
}
}
示例6: getUploadedFileTokenByFileNameAction
/**
*
* @action getUploadedFileTokenByFileName
* @param string $fileName
* @return KalturaUploadResponse
*/
function getUploadedFileTokenByFileNameAction($fileName)
{
KalturaResponseCacher::disableConditionalCache();
$res = new KalturaUploadResponse();
$ksUnique = md5($this->getKs()->toSecureString());
$uniqueId = md5($fileName);
$ext = pathinfo($fileName, PATHINFO_EXTENSION);
$token = $ksUnique . "_" . $uniqueId . "." . $ext;
$entryFullPath = myUploadUtils::getUploadPath($token, "", null, strtolower($ext));
// filesync ok
if (!file_exists($entryFullPath)) {
throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
}
$res->uploadTokenId = $token;
$res->fileSize = kFile::fileSize($entryFullPath);
return $res;
}
示例7: __construct
public function __construct($filePath, $mimeType, $xSendFileAllowed, $maxAge = 8640000, $limitFileSize = 0)
{
$this->filePath = $filePath;
$this->mimeType = $mimeType;
$this->maxAge = $maxAge;
$this->fileExt = pathinfo($filePath, PATHINFO_EXTENSION);
if ($limitFileSize) {
$this->fileSize = $limitFileSize;
$this->xSendFileAllowed = false;
} else {
clearstatcache();
$this->fileSize = kFile::fileSize($filePath);
$this->xSendFileAllowed = $xSendFileAllowed;
}
if ($this->fileSize && $this->fileSize < self::CACHE_FILE_CONTENTS_MAX_SIZE) {
$this->fileData = file_get_contents($this->filePath, false, null, -1, $limitFileSize);
}
}
示例8: execute
//.........这里部分代码省略.........
// milliseconds
if (is_null($clipTo)) {
$clipTo = $this->getRequestParameter("clipTo", self::NO_CLIP_TO);
}
// milliseconds
if ($clipTo == 0) {
$clipTo = self::NO_CLIP_TO;
}
if (!is_numeric($clipTo) || $clipTo < 0) {
KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'clipTo must be a positive number');
}
$seekFrom = $this->getRequestParameter("seekFrom", -1);
if ($seekFrom <= 0) {
$seekFrom = -1;
}
$seekFromBytes = $this->getRequestParameter("seekFromBytes", -1);
if ($seekFromBytes <= 0) {
$seekFromBytes = -1;
}
if ($fileParam && is_dir($path)) {
$path .= "/{$fileParam}";
kFileUtils::dumpFile($path, null, null);
KExternalErrors::dieGracefully();
} else {
if (!$isFlv || $clipTo == self::NO_CLIP_TO && $seekFrom < 0 && $seekFromBytes < 0) {
$limit_file_size = 0;
if ($clipTo != self::NO_CLIP_TO) {
if (strtolower($flavorAsset->getFileExt()) == 'mp4' && PermissionPeer::isValidForPartner(PermissionName::FEATURE_ACCURATE_SERVE_CLIPPING, $flavorAsset->getPartnerId())) {
$contentPath = myContentStorage::getFSContentRootPath();
$tempClipName = $version . '_' . $clipTo . '.mp4';
$tempClipPath = $contentPath . myContentStorage::getGeneralEntityPath("entry/tempclip", $flavorAsset->getIntId(), $flavorAsset->getId(), $tempClipName);
if (!file_exists($tempClipPath)) {
kFile::fullMkdir($tempClipPath);
$clipToSec = round($clipTo / 1000, 3);
$cmdLine = kConf::get("bin_path_ffmpeg") . " -i {$path} -vcodec copy -acodec copy -f mp4 -t {$clipToSec} -y {$tempClipPath} 2>&1";
KalturaLog::log("Executing {$cmdLine}");
$output = array();
$return_value = "";
exec($cmdLine, $output, $return_value);
KalturaLog::log("ffmpeg returned {$return_value}, output:" . implode("\n", $output));
}
if (file_exists($tempClipPath)) {
KalturaLog::log("Dumping {$tempClipPath}");
kFileUtils::dumpFile($tempClipPath);
} else {
KalturaLog::err('Failed to clip the file using ffmpeg, falling back to rough clipping');
}
}
$mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
$duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
$limit_file_size = floor(@kFile::fileSize($path) * ($clipTo / $duration) * 1.2);
}
}
$renderer = kFileUtils::getDumpFileRenderer($path, null, null, $limit_file_size);
if (!$fileName) {
$this->storeCache($renderer, $flavorAsset->getPartnerId());
}
$renderer->output();
KExternalErrors::dieGracefully();
}
}
$audioOnly = $this->getRequestParameter("audioOnly");
// milliseconds
if ($audioOnly === '0') {
// audioOnly was explicitly set to 0 - don't attempt to make further automatic investigations
} elseif ($flvWrapper->getFirstVideoTimestamp() < 0) {
$audioOnly = true;
}
$bytes = 0;
if ($seekFrom !== -1 && $seekFrom !== 0) {
list($bytes, $duration, $firstTagByte, $toByte) = $flvWrapper->clip(0, -1, $audioOnly);
list($bytes, $duration, $fromByte, $toByte, $seekFromTimestamp) = $flvWrapper->clip($seekFrom, -1, $audioOnly);
$seekFromBytes = myFlvHandler::FLV_HEADER_SIZE + $flvWrapper->getMetadataSize($audioOnly) + $fromByte - $firstTagByte;
} else {
list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly);
}
$metadataSize = $flvWrapper->getMetadataSize($audioOnly);
$dataOffset = $metadataSize + myFlvHandler::getHeaderSize();
$totalLength = $dataOffset + $bytes;
list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly);
list($rangeFrom, $rangeTo, $rangeLength) = requestUtils::handleRangeRequest($totalLength);
if ($totalLength < 1000) {
// (actually $total_length is probably 13 or 143 - header + empty metadata tag) probably a bad flv maybe only the header - dont cache
requestUtils::sendCdnHeaders("flv", $rangeLength, 0);
} else {
requestUtils::sendCdnHeaders("flv", $rangeLength);
}
// dont inject cuepoint into the stream
$cuepointTime = 0;
$cuepointPos = 0;
try {
Propel::close();
} catch (Exception $e) {
$this->logMessage("serveFlavor: error closing db {$e}");
}
header("Content-Type: video/x-flv");
$flvWrapper->dump(self::CHUNK_SIZE, $fromByte, $toByte, $audioOnly, $seekFromBytes, $rangeFrom, $rangeTo, $cuepointTime, $cuepointPos);
KExternalErrors::dieGracefully();
}
示例9: validateResource
/**
* Validates if the resource is valid
* @param KalturaResource $resource
* @param SimpleXMLElement $elementToSearchIn
*/
protected function validateResource(KalturaResource $resource = null, SimpleXMLElement $elementToSearchIn)
{
if (!$resource) {
return;
}
//We only check for filesize and check sum in local files
if ($resource instanceof KalturaServerFileResource) {
$filePath = $resource->localFilePath;
if (is_null($filePath)) {
throw new KalturaBulkUploadXmlException("Can't validate file as file path is null", KalturaBatchJobAppErrors::BULK_ITEM_VALIDATION_FAILED);
}
if (isset($elementToSearchIn->serverFileContentResource->fileChecksum)) {
KalturaLog::debug("Validating checksum");
if ($elementToSearchIn->serverFileContentResource->fileChecksum['type'] == 'sha1') {
$checksum = sha1_file($filePath);
} else {
$checksum = md5_file($filePath);
}
$xmlChecksum = (string) $elementToSearchIn->serverFileContentResource->fileChecksum;
if ($xmlChecksum != $checksum) {
throw new KalturaBulkUploadXmlException("File checksum is invalid for file [{$filePath}], Xml checksum [{$xmlChecksum}], actual checksum [{$checksum}]", KalturaBatchJobAppErrors::BULK_ITEM_VALIDATION_FAILED);
}
}
if (isset($elementToSearchIn->serverFileContentResource->fileSize)) {
KalturaLog::debug("Validating file size");
$fileSize = kFile::fileSize($filePath);
$xmlFileSize = (int) $elementToSearchIn->serverFileContentResource->fileSize;
if ($xmlFileSize != $fileSize) {
throw new KalturaBulkUploadXmlException("File size is invalid for file [{$filePath}], Xml size [{$xmlFileSize}], actual size [{$fileSize}]", KalturaBatchJobAppErrors::BULK_ITEM_VALIDATION_FAILED);
}
}
}
}
示例10: moveFile
/**
* @param KalturaBatchJob $job
* @param string $destFile
* @param int $fileSize
* @return KalturaBatchJob
*/
private function moveFile(KalturaBatchJob $job, $destFile, $fileSize = null)
{
KalturaLog::debug("moveFile({$job->id}, {$destFile}, {$fileSize})");
try {
// creates a shared file path
$rootPath = $this->taskConfig->params->sharedTempPath;
$res = self::createDir($rootPath);
if (!$res) {
KalturaLog::err("Cannot continue import without shared directory");
die;
}
$uniqid = uniqid('import_');
$sharedFile = realpath($rootPath) . "/{$uniqid}";
$ext = pathinfo($destFile, PATHINFO_EXTENSION);
if (strlen($ext)) {
$sharedFile .= ".{$ext}";
}
KalturaLog::debug("rename('{$destFile}', '{$sharedFile}')");
rename($destFile, $sharedFile);
if (!file_exists($sharedFile)) {
KalturaLog::err("Error: renamed file doesn't exist");
die;
}
clearstatcache();
if ($fileSize) {
if (kFile::fileSize($sharedFile) != $fileSize) {
KalturaLog::err("Error: renamed file have a wrong size");
die;
}
} else {
$fileSize = kFile::fileSize($sharedFile);
}
@chmod($sharedFile, 0777);
$data = $job->data;
$data->destFileLocalPath = $sharedFile;
if ($this->checkFileExists($sharedFile, $fileSize)) {
$this->closeJob($job, null, null, 'Succesfully moved file', KalturaBatchJobStatus::FINISHED, $data);
} else {
$this->closeJob($job, KalturaBatchJobErrorTypes::APP, KalturaBatchJobAppErrors::NFS_FILE_DOESNT_EXIST, 'File not moved correctly', KalturaBatchJobStatus::RETRY);
}
} catch (Exception $ex) {
$this->closeJob($job, KalturaBatchJobErrorTypes::RUNTIME, $ex->getCode(), "Error: " . $ex->getMessage(), KalturaBatchJobStatus::FAILED);
}
return $job;
}
示例11: putObject
/**
* Put an object
*
* @param mixed $input Input data
* @param string $bucket Bucket name
* @param string $uri Object URI
* @param constant $acl ACL constant
* @param array $metaHeaders Array of x-amz-meta-* headers
* @param array $requestHeaders Array of request headers or content type as a string
* @param constant $storageClass Storage class constant
* @return boolean
*/
public static function putObject($input, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $requestHeaders = array(), $storageClass = self::STORAGE_CLASS_STANDARD)
{
if ($input === false) {
return false;
}
$rest = new S3Request('PUT', $bucket, $uri, self::$endpoint);
if (is_string($input)) {
$input = array('data' => $input, 'size' => strlen($input), 'md5sum' => base64_encode(md5($input, true)));
}
// Data
if (isset($input['fp'])) {
$rest->fp =& $input['fp'];
} elseif (isset($input['file'])) {
$rest->fp = @fopen($input['file'], 'rb');
} elseif (isset($input['data'])) {
$rest->data = $input['data'];
}
// Content-Length (required)
if (isset($input['size']) && $input['size'] >= 0) {
$rest->size = $input['size'];
} else {
if (isset($input['file'])) {
$rest->size = kFile::fileSize($input['file']);
} elseif (isset($input['data'])) {
$rest->size = strlen($input['data']);
}
}
// Custom request headers (Content-Type, Content-Disposition, Content-Encoding)
if (is_array($requestHeaders)) {
foreach ($requestHeaders as $h => $v) {
$rest->setHeader($h, $v);
}
} elseif (is_string($requestHeaders)) {
// Support for legacy contentType parameter
$input['type'] = $requestHeaders;
}
// Content-Type
if (!isset($input['type'])) {
if (isset($requestHeaders['Content-Type'])) {
$input['type'] =& $requestHeaders['Content-Type'];
} elseif (isset($input['file'])) {
$input['type'] = self::__getMimeType($input['file']);
} else {
$input['type'] = 'application/octet-stream';
}
}
if ($storageClass !== self::STORAGE_CLASS_STANDARD) {
// Storage class
$rest->setAmzHeader('x-amz-storage-class', $storageClass);
}
// We need to post with Content-Length and Content-Type, MD5 is optional
if ($rest->size >= 0 && ($rest->fp !== false || $rest->data !== false)) {
$rest->setHeader('Content-Type', $input['type']);
if (isset($input['md5sum'])) {
$rest->setHeader('Content-MD5', $input['md5sum']);
}
$rest->setAmzHeader('x-amz-acl', $acl);
foreach ($metaHeaders as $h => $v) {
$rest->setAmzHeader('x-amz-meta-' . $h, $v);
}
$rest->getResponse();
} else {
$rest->response->error = array('code' => 0, 'message' => 'Missing input parameters');
}
if ($rest->response->error === false && $rest->response->code !== 200) {
$rest->response->error = array('code' => $rest->response->code, 'message' => 'Unexpected HTTP status');
}
if ($rest->response->error !== false) {
self::__triggerError(sprintf("S3::putObject(): [%s] %s", $rest->response->error['code'], $rest->response->error['message']), __FILE__, __LINE__);
return false;
}
return true;
}
示例12: checkFileExists
/**
* @param string $file
* @param int $size
* @return bool
*/
protected function checkFileExists($file, $size = null, $directorySync = null)
{
$this->setFilePermissions($file);
if ($this->isUnitTest) {
KalturaLog::debug("Is in unit test");
return true;
}
// If this is not a file but a directory, certain operations should be done diffrently:
// - size calcultions
// - the response from the client (to check the client size beaviour)
if (is_null($directorySync)) {
$directorySync = is_dir($file);
}
KalturaLog::info("Check File Exists[{$file}] size[{$size}] isDir[{$directorySync}]");
if (is_null($size)) {
clearstatcache();
if ($directorySync) {
$size = KBatchBase::foldersize($file);
} else {
$size = kFile::fileSize($file);
}
if ($size === false) {
KalturaLog::debug("Size not found on file [{$file}]");
return false;
}
}
$retries = self::$taskConfig->fileExistReties ? self::$taskConfig->fileExistReties : 1;
$interval = self::$taskConfig->fileExistInterval ? self::$taskConfig->fileExistInterval : 5;
while ($retries > 0) {
$check = self::$kClient->batch->checkFileExists($file, $size);
// In case of directorySync - do not check client sizeOk - to be revised
if ($check->exists && ($check->sizeOk || $directorySync)) {
$this->onFileEvent($file, $size, KBatchEvent::EVENT_FILE_EXISTS);
return true;
}
$this->onFileEvent($file, $size, KBatchEvent::EVENT_FILE_DOESNT_EXIST);
sleep($interval);
$retries--;
}
KalturaLog::log("Passed max retries");
return false;
}
示例13: execute
//.........这里部分代码省略.........
$level3_url = $request . $flv_extension;
if ($entry->getSecurityPolicy()) {
$level3_url = "/s{$level3_url}";
// set expire time in GMT hence the date("Z") offset
$expire = "&nva=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + 30);
$level3_url .= $expire;
$secret = kConf::get("level3_authentication_key");
$hash = "0" . substr(self::hmac('sha1', $secret, $level3_url), 0, 20);
$level3_url .= "&h={$hash}";
}
$level3_url .= $seek_from_bytes == -1 ? "" : "&start={$seek_from_bytes}";
header("Location: {$level3_url}");
KExternalErrors::dieGracefully();
} else {
if ($cdn_name == "akamai") {
$akamai_url = $request . $flv_extension;
// if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
if ($seek_from_timestamp == -1) {
$seek_from_timestamp = $seek_from;
}
$akamai_url .= $seek_from_bytes == -1 ? "" : "&aktimeoffset=" . floor($seek_from_timestamp / 1000);
header("Location: {$akamai_url}");
KExternalErrors::dieGracefully();
}
}
}
// a seek request without a supporting cdn - we need to send the answer from our server
if ($seek_from_bytes !== -1 && $via_header === null) {
$this->dump_from_byte = $seek_from_bytes;
}
}
}
// always add the file suffix to the request (needed for scrubbing by some cdns,
// and also breaks without extension on some corporate antivirus).
// we add the the novar paramter since a leaving a trailing "?" will be trimmed
// and then the /seek_from request will result in another url which level3
// will try to refetch from the origin
// note that for streamer we dont add the file extension
if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) {
// a seek request without a supporting cdn - we need to send the answer from our server
if ($seek_from_bytes !== -1 && $via_header === null) {
$request .= "/seek_from_bytes/{$seek_from_bytes}";
}
requestUtils::sendCdnHeaders("flv", 0);
header("Location: {$request}" . $flv_extension);
KExternalErrors::dieGracefully();
}
// mp4
if (!$isFlv) {
$limit_file_size = 0;
if ($clip_to != 2147483647) {
$mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
$duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
$limit_file_size = floor(@kFile::fileSize($path) * ($clip_to / $duration) * 1.2);
}
}
KalturaLog::info("serving file [{$path}] entry id [{$entry_id}] limit file size [{$limit_file_size}] clip_to [{$clip_to}]");
kFileUtils::dumpFile($path, null, null, $limit_file_size);
}
$this->logMessage("flvclipperAction: serving file [{$path}] entry_id [{$entry_id}] clip_from [{$clip_from}] clip_to [{$clip_to}]", "warning");
if ($audio_only === '0') {
// audio_only was explicitly set to 0 - don't attempt to make further automatic investigations
} elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) {
$audio_only = true;
}
//$start = microtime(true);
list($bytes, $duration, $from_byte, $to_byte, $from_ts, $cuepoint_pos) = myFlvStaticHandler::clip($path, $clip_from, $clip_to, $audio_only);
$metadata_size = $flv_wrapper->getMetadataSize($audio_only);
$this->from_byte = $from_byte;
$this->to_byte = $to_byte;
//$end1 = microtime(true);
//$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" );
//$this->logMessage( "flvclipperAction: serving file [$path] t1 [" . ( $end1-$start) . "]");
$data_offset = $metadata_size + myFlvHandler::getHeaderSize();
// if we're returning a partial file adjust the total size:
// substract the metadata and bytes which are not delivered
if ($this->dump_from_byte >= $data_offset && !$audio_only) {
$bytes -= $metadata_size + max(0, $this->dump_from_byte - $data_offset);
}
$this->total_length = $data_offset + $bytes;
//echo " $bytes , $duration ,$from_byte , $to_byte, $cuepoint_pos\n"; die;
$this->cuepoint_time = 0;
$this->cuepoint_pos = 0;
if ($streamer == "chunked" && $clip_to != 2147483647) {
$this->cuepoint_time = $clip_to - 1;
$this->cuepoint_pos = $cuepoint_pos;
$this->total_length += myFlvHandler::CUEPOINT_TAG_SIZE;
}
//$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes with header & md [" . $this->total_length . "] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" );
$this->flv_wrapper = $flv_wrapper;
$this->audio_only = $audio_only;
try {
Propel::close();
} catch (Exception $e) {
$this->logMessage("flvclipperAction: error closing db {$e}");
}
KExternalErrors::terminateDispatch();
return sfView::SUCCESS;
}
示例14: fetchFile
/**
* @param string $srcFileSyncRemoteUrl
* @param string $srcFileSyncLocalPath
* @param string $errDescription
* @return string
*/
private function fetchFile($srcFileSyncRemoteUrl, $srcFileSyncLocalPath, &$errDescription = null)
{
KalturaLog::debug("fetchFile({$srcFileSyncRemoteUrl}, {$srcFileSyncLocalPath})");
try {
$curlWrapper = new KCurlWrapper($srcFileSyncRemoteUrl);
$curlHeaderResponse = $curlWrapper->getHeader(true);
if (!$curlHeaderResponse || $curlWrapper->getError()) {
$errDescription = "Error: " . $curlWrapper->getError();
return false;
}
if ($curlHeaderResponse->code != KCurlHeaderResponse::HTTP_STATUS_OK) {
$errDescription = "HTTP Error: " . $curlHeaderResponse->code . " " . $curlHeaderResponse->codeName;
return false;
}
$fileSize = null;
KalturaLog::debug("Headers:\n" . print_r($curlHeaderResponse->headers, true));
if (isset($curlHeaderResponse->headers['content-length'])) {
$fileSize = $curlHeaderResponse->headers['content-length'];
}
$curlWrapper->close();
if ($fileSize && file_exists($srcFileSyncLocalPath)) {
clearstatcache();
$actualFileSize = kFile::fileSize($srcFileSyncLocalPath);
if ($actualFileSize == $fileSize) {
KalturaLog::log("File [{$srcFileSyncLocalPath}] already exists with right size[{$fileSize}]");
return true;
}
KalturaLog::log("File [{$srcFileSyncLocalPath}] already exists with wrong size[{$actualFileSize}] expected size[{$fileSize}]");
KalturaLog::debug("Unlink file[{$srcFileSyncLocalPath}]");
unlink($srcFileSyncLocalPath);
}
KalturaLog::debug("Executing curl");
$curlWrapper = new KCurlWrapper($srcFileSyncRemoteUrl);
$res = $curlWrapper->exec($srcFileSyncLocalPath);
KalturaLog::debug("Curl results: {$res}");
if (!$res || $curlWrapper->getError()) {
$errDescription = "Error: " . $curlWrapper->getError();
$curlWrapper->close();
return false;
}
$curlWrapper->close();
if (!file_exists($srcFileSyncLocalPath)) {
$errDescription = "Error: output file[{$srcFileSyncLocalPath}] doesn't exist";
return false;
}
clearstatcache();
$actualFileSize = kFile::fileSize($srcFileSyncLocalPath);
KalturaLog::debug("Fetched file to [{$srcFileSyncLocalPath}] size[{$actualFileSize}]");
if ($fileSize) {
if ($actualFileSize != $fileSize) {
$errDescription = "Error: output file[{$srcFileSyncLocalPath}] have a wrong size[{$actualFileSize}] expected size[{$fileSize}]";
return false;
}
}
} catch (Exception $ex) {
$errDescription = "Error: " . $ex->getMessage();
return false;
}
return true;
}
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:66,代码来源:KAsyncConvertCollectionCloser.class.php
示例15: moveFiles
private function moveFiles(KalturaBatchJob $job, KalturaConvertCollectionJobData $data)
{
KalturaLog::debug("moveFiles(destDirLocalPath [{$data->destDirLocalPath}])");
clearstatcache();
$files2move = array();
$fileNames = array($data->destFileName . '.log', $data->destFileName . '.ism', $data->destFileName . '.ismc', $data->destFileName . '_Thumb.jpg');
foreach ($fileNames as $fileName) {
$srcPath = $data->destDirLocalPath . DIRECTORY_SEPARATOR . $fileName;
if (!file_exists($srcPath)) {
continue;
}
$destPath = $this->sharedTempPath . DIRECTORY_SEPARATOR . $fileName;
$sharedPath = $this->translateLocalPath2Shared($destPath);
$fileSize = kFile::fileSize($srcPath);
KalturaLog::debug("add to move list file[{$srcPath}] to[{$destPath}] size[{$fileSize}] shared path[{$sharedPath}]");
$files2move[] = array('from' => $srcPath, 'to' => $destPath, 'path' => $sharedPath, 'size' => $fileSize);
}
foreach ($data->flavors as $flavor) {
$srcPath = $flavor->destFileSyncLocalPath;
if (!file_exists($srcPath)) {
continue;
}
$destPath = $this->sharedTempPath . DIRECTORY_SEPARATOR . basename($srcPath);
$sharedPath = $this->translateLocalPath2Shared($destPath);
$fileSize = kFile::fileSize($srcPath);
$flavor->destFileSyncLocalPath = $sharedPath;
if ($this->taskConfig->params->isRemoteOutput) {
$flavor->destFileSyncRemoteUrl = $this->distributedFileManager->getRemoteUrl($sharedPath);
}
KalturaLog::debug("add to move list file[{$srcPath}] to[{$destPath}] size[{$fileSize}] shared path[{$sharedPath}]");
$files2move[] = array('from' => $srcPath, 'to' => $destPath, 'path' => $sharedPath, 'size' => $fileSize);
}
foreach ($files2move as $file2move) {
$srcPath = $file2move['from'];
$destPath = $file2move['to'];
$fileSize = $file2move['size'];
KalturaLog::debug("moving file[{$srcPath}] to[{$destPath}] size[{$fileSize}]");
if (file_exists($destPath)) {
KalturaLog::debug("delete existing file[{$destPath}]");
unlink($destPath);
}
KalturaLog::debug("rename({$srcPath}, {$destPath})");
rename($srcPath, $destPath);
if (!file_exists($destPath) || kFile::fileSize($destPath) != $fileSize) {
KalturaLog::err("Error: moving file [{$srcPath}] failed");
die;
}
@chmod($destPath, 0777);
}
$data->destDirLocalPath = $this->translateLocalPath2Shared($this->sharedTempPath);
if ($this->taskConfig->params->isRemoteOutput) {
$data->destDirRemoteUrl = $this->distributedFileManager->getRemoteUrl($data->destDirLocalPath);
$job->status = KalturaBatchJobStatus::ALMOST_DONE;
$job->message = "Files ready for download";
} elseif ($this->checkFilesArrayExist($files2move)) {
$job->status = KalturaBatchJobStatus::FINISHED;
$job->message = "Files moved to shared";
} else {
$job->status = KalturaBatchJobStatus::RETRY;
$job->message = "Files not moved correctly";
}
return $this->closeJob($job, null, null, $job->message, $job->status, $data);
}
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:63,代码来源:KAsyncConvertCollection.class.php