本文整理汇总了PHP中kFile::listDir方法的典型用法代码示例。如果您正苦于以下问题:PHP kFile::listDir方法的具体用法?PHP kFile::listDir怎么用?PHP kFile::listDir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kFile
的用法示例。
在下文中一共展示了kFile::listDir方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: moveFile
private function moveFile(KalturaBatchJob $job, $fromPath, $toPath)
{
KalturaLog::debug("moveFile from[{$fromPath}] to[{$toPath}]");
// move file/dir to the new location
$res = @rename($fromPath, $toPath);
// chmod + chown + check file seen by apache - for each moved file/directory
if ($res) {
if (is_dir($toPath)) {
$contents = kFile::listDir($toPath);
sort($contents, SORT_STRING);
foreach ($contents as $current) {
$res = $res && $this->setAndCheck($toPath . '/' . $current);
}
} else {
$res = $this->setAndCheck($toPath);
}
}
if ($res) {
$job->status = KalturaBatchJobStatus::FINISHED;
$job->message = "File moved to final destination";
} else {
$job->status = KalturaBatchJobStatus::FAILED;
$job->message = "File not moved correctly";
}
return $this->closeJob($job, null, null, $job->message, $job->status, null, $job->data);
}
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:26,代码来源:KAsyncFileSyncImportCloser.class.php
示例2: listDir
/**
* Returns directory $path contents as an array of :
* array[0] = name
* array[1] = type (dir/file)
* array[2] = filesize
* @param string $path
* @param string $pathPrefix
*/
public static function listDir($path, $pathPrefix = '')
{
$fileList = array();
$path = str_ireplace(DIRECTORY_SEPARATOR, '/', $path);
$handle = opendir($path);
if ($handle) {
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
$fullPath = $path . '/' . $file;
$tmpPrefix = $pathPrefix . $file;
if (is_dir($fullPath)) {
$tmpPrefix = $tmpPrefix . '/';
$fileList[] = array($tmpPrefix, 'dir', kFile::fileSize($fullPath));
$fileList = array_merge($fileList, kFile::listDir($fullPath, $tmpPrefix));
} else {
$fileList[] = array($tmpPrefix, 'file', kFile::fileSize($fullPath));
}
}
}
closedir($handle);
}
return $fileList;
}
示例3: serveFileToRemoteDataCenter
public static function serveFileToRemoteDataCenter($file_sync, $file_hash, $file_name)
{
$file_sync_id = $file_sync->getId();
KalturaLog::log("File sync id [{$file_sync_id}], file_hash [{$file_hash}], file_name [{$file_name}]");
// TODO - verify security
$current_dc = self::getCurrentDc();
$current_dc_id = $current_dc["id"];
if ($file_sync->getDc() != $current_dc_id) {
$error = "DC[{$current_dc_id}]: FileSync with id [{$file_sync_id}] does not belong to this DC";
KalturaLog::err($error);
KExternalErrors::dieError(KExternalErrors::BAD_QUERY);
}
// resolve if file_sync is link
$file_sync_resolved = $file_sync;
$file_sync_resolved = kFileSyncUtils::resolve($file_sync);
// check if file sync path leads to a file or a directory
$resolvedPath = $file_sync_resolved->getFullPath();
$fileSyncIsDir = is_dir($resolvedPath);
if ($fileSyncIsDir && $file_name) {
$resolvedPath .= '/' . $file_name;
}
if (!file_exists($resolvedPath)) {
$file_name_msg = $file_name ? "file name [{$file_name}] " : '';
$error = "DC[{$current_dc_id}]: Path for fileSync id [{$file_sync_id}] " . $file_name_msg . "does not exist, resolved path [{$resolvedPath}]";
KalturaLog::err($error);
KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
}
// validate the hash
$expected_file_hash = md5($current_dc["secret"] . $file_sync_id);
// will be verified on the other side to make sure not some attack or external invalid request
if ($file_hash != $expected_file_hash) {
$error = "DC[{$current_dc_id}]: FileSync with id [{$file_sync_id}] - invalid hash";
KalturaLog::err($error);
KExternalErrors::dieError(KExternalErrors::INVALID_TOKEN);
}
if ($fileSyncIsDir && is_dir($resolvedPath)) {
KalturaLog::log("Serving directory content from [" . $resolvedPath . "]");
$contents = kFile::listDir($resolvedPath);
sort($contents, SORT_STRING);
$contents = serialize($contents);
header("file-sync-type: dir");
echo $contents;
KExternalErrors::dieGracefully();
} else {
KalturaLog::log("Serving file from [" . $resolvedPath . "]");
kFileUtils::dumpFile($resolvedPath);
}
}
示例4: serveFileToRemoteDataCenter
public static function serveFileToRemoteDataCenter($file_sync_id, $file_hash, $file_name)
{
KalturaLog::log("File sync id [{$file_sync_id}], file_hash [{$file_hash}], file_name [{$file_name}]");
// TODO - verify security
$current_dc = self::getCurrentDc();
$current_dc_id = $current_dc["id"];
// retrieve the object
$file_sync = FileSyncPeer::retrieveByPk($file_sync_id);
if (!$file_sync) {
$error = "DC[{$current_dc_id}]: Cannot find FileSync with id [{$file_sync_id}]";
KalturaLog::err($error);
throw new Exception($error);
}
if ($file_sync->getDc() != $current_dc_id) {
$error = "DC[{$current_dc_id}]: FileSync with id [{$file_sync_id}] does not belong to this DC";
KalturaLog::err($error);
throw new Exception($error);
}
// resolve if file_sync is link
$file_sync_resolved = $file_sync;
if ($file_sync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_LINK) {
$file_sync_resolved = kFileSyncUtils::resolve($file_sync);
}
// check if file sync path leads to a file or a directory
$resolvedPath = $file_sync_resolved->getFullPath();
$fileSyncIsDir = is_dir($resolvedPath);
if ($fileSyncIsDir && $file_name) {
$resolvedPath .= '/' . $file_name;
}
if (!file_exists($resolvedPath)) {
$file_name_msg = $file_name ? "file name [{$file_name}] " : '';
$error = "DC[{$current_dc_id}]: Path for fileSync id [{$file_sync_id}] " . $file_name_msg . "does not exist";
KalturaLog::err($error);
throw new Exception($error);
}
// validate the hash
$expected_file_hash = md5($current_dc["secret"] . $file_sync_id);
// will be verified on the other side to make sure not some attack or external invalid request
if ($file_hash != $expected_file_hash) {
$error = "DC[{$current_dc_id}]: FileSync with id [{$file_sync_id}] - invalid hash";
KalturaLog::err($error);
throw new Exception($error);
}
if ($fileSyncIsDir && is_dir($resolvedPath)) {
KalturaLog::log("Serving directory content from [" . $resolvedPath . "]");
$contents = kFile::listDir($resolvedPath);
sort($contents, SORT_STRING);
$contents = serialize($contents);
header("file-sync-type: dir");
echo $contents;
die;
} else {
KalturaLog::log("Serving file from [" . $resolvedPath . "]");
kFile::dumpFile($resolvedPath);
}
}