本文整理汇总了PHP中sha1_file函数的典型用法代码示例。如果您正苦于以下问题:PHP sha1_file函数的具体用法?PHP sha1_file怎么用?PHP sha1_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sha1_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
/**
* Handles uploaded files.
*/
public function upload()
{
// save files
$files = $this->parameters['__files']->getFiles();
$file = $files[0];
try {
if (!$file->getValidationErrorType()) {
$data = array('userID' => WCF::getUser()->userID ?: null, 'filename' => $file->getFilename(), 'fileType' => $file->getMimeType(), 'fileHash' => sha1_file($file->getLocation()), 'filesize' => $file->getFilesize(), 'uploadTime' => TIME_NOW);
// save file
$upload = FileUploadEditor::create($data);
// move uploaded file
if (@copy($file->getLocation(), $upload->getLocation())) {
@unlink($file->getLocation());
// return result
return array('uploadID' => $upload->uploadID, 'filename' => $upload->filename, 'filesize' => $upload->filesize, 'formattedFilesize' => FileUtil::formatFilesize($upload->filesize));
} else {
// moving failed; delete file
$editor = new FileUploadEditor($upload);
$editor->delete();
throw new UserInputException('fileUpload', 'uploadFailed');
}
}
} catch (UserInputException $e) {
$file->setValidationErrorType($e->getType());
}
return array('errorType' => $file->getValidationErrorType());
}
示例2: get_plugins_supporting_mobile
/**
* Returns a list of Moodle plugins supporting the mobile app.
*
* @return array an array of objects containing the plugin information
*/
public static function get_plugins_supporting_mobile()
{
global $CFG;
require_once $CFG->libdir . '/adminlib.php';
$pluginsinfo = [];
$plugintypes = core_component::get_plugin_types();
foreach ($plugintypes as $plugintype => $unused) {
// We need to include files here.
$pluginswithfile = core_component::get_plugin_list_with_file($plugintype, 'db' . DIRECTORY_SEPARATOR . 'mobile.php');
foreach ($pluginswithfile as $plugin => $notused) {
$path = core_component::get_plugin_directory($plugintype, $plugin);
$component = $plugintype . '_' . $plugin;
$version = get_component_version($component);
require_once "{$path}/db/mobile.php";
foreach ($addons as $addonname => $addoninfo) {
$plugininfo = array('component' => $component, 'version' => $version, 'addon' => $addonname, 'dependencies' => !empty($addoninfo['dependencies']) ? $addoninfo['dependencies'] : array(), 'fileurl' => '', 'filehash' => '', 'filesize' => 0);
// All the mobile packages must be under the plugin mobile directory.
$package = $path . DIRECTORY_SEPARATOR . 'mobile' . DIRECTORY_SEPARATOR . $addonname . '.zip';
if (file_exists($package)) {
$plugininfo['fileurl'] = $CFG->wwwroot . '' . str_replace($CFG->dirroot, '', $package);
$plugininfo['filehash'] = sha1_file($package);
$plugininfo['filesize'] = filesize($package);
}
$pluginsinfo[] = $plugininfo;
}
}
}
return $pluginsinfo;
}
示例3: checksum
/**
* Returns the SHA1 checksum of the given file
*
* @param string $file Path to file
*
* @return string Checksum or empty string if file doesn't exist
*/
public function checksum($file)
{
if (file_exists($file)) {
return sha1_file($file);
}
return '';
}
示例4: getDirsChecksums
public static function getDirsChecksums($_dir, $_opts = array())
{
$dirs = is_array($_dir) ? $_dir : array($_dir);
sort($dirs);
$files = array();
$ignore = isset($_opts["ignore"]) ? $_opts["ignore"] : null;
$substDir = isset($_opts["substDir"]) ? $_opts["substDir"] : false;
foreach ($dirs as $dir) {
$dirLength = strlen($dir);
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir)) as $path => $fileinfo) {
if (!$fileinfo->isFile()) {
continue;
}
$key = $substDir ? substr($path, $dirLength) : $path;
if (DIRECTORY_SEPARATOR !== "/") {
$key = str_replace(DIRECTORY_SEPARATOR, "/", $key);
}
if ($ignore && preg_match($ignore, $key)) {
continue;
}
$files[$key] = sha1_file($path);
}
}
ksort($files);
return $files;
}
示例5: processDeposit
/**
* {@inheritdoc}
*/
protected function processDeposit(Deposit $deposit)
{
$depositPath = $this->filePaths->getHarvestFile($deposit);
if (!$this->fs->exists($depositPath)) {
throw new Exception("Cannot find deposit bag {$depositPath}");
}
$checksumValue = null;
switch (strtoupper($deposit->getChecksumType())) {
case 'SHA-1':
case 'SHA1':
$checksumValue = sha1_file($depositPath);
break;
case 'MD5':
$checksumValue = md5_file($depositPath);
break;
default:
throw new Exception("Deposit checksum type {$deposit->getChecksumType()} unknown.");
}
if (strtoupper($checksumValue) !== $deposit->getChecksumValue()) {
$deposit->addErrorLog("Deposit checksum does not match. Expected {$deposit->getChecksumValue()} != Actual " . strtoupper($checksumValue));
$this->logger->warning("Deposit checksum does not match for deposit {$deposit->getDepositUuid()}");
return false;
}
$this->logger->info("Deposit {$depositPath} validated.");
return true;
}
示例6: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$videos = glob(public_path() . '/b/*');
usort($videos, function ($a, $b) {
$a = (int) basename($a, '.webm');
$b = (int) basename($b, '.webm');
if ($a == $b) {
return 0;
}
return $a < $b ? -1 : 1;
});
$category = \App\Models\Category::where('shortname', '=', 'misc')->first();
$user = \App\Models\User::find(1);
foreach ($videos as $video) {
if (\App\Models\Video::whereFile(basename($video))->count() > 0) {
continue;
}
$v = new \App\Models\Video();
$v->user()->associate($user);
$v->category()->associate($category);
$v->hash = sha1_file($video);
$v->file = basename($video);
$v->save();
}
}
示例7: compare
function compare($dir, $racine)
{
$retour = 'terminée avec succès.<br>';
$files = array_diff(scandir($dir), array('.', '..'));
foreach ($files as $file) {
if (is_dir($dir . $file)) {
if (file_exists($racine . $file)) {
compare($dir . $file . '/', $racine . $file . '/');
} else {
mkdir($racine . $file);
}
} else {
if (file_exists($racine . $file)) {
$shaNow = sha1_file($racine . $file);
$shaNext = sha1_file($dir . $file);
if ($shaNow != $shaNext) {
if (filemtime($dir . $file) >= filemtime($racine . $file)) {
$retour .= $racine . $file . ' Le fichier actuel a une date de modification plus récente<br>';
} else {
transfertFile($dir . '/' . $file, $racine . $file);
}
}
} else {
transfertFile($dir . '/' . $file, $racine . $file);
}
}
}
return $retour;
}
示例8: readXmlDocument
public function readXmlDocument($file, $cli = false)
{
try {
if ($cli) {
if (!$file) {
throw new XmlValidatorException("The file argument is missing!");
} else {
if (!file_exists($file)) {
throw new XmlValidatorException("The input file: " . $file . " does't exist!");
} else {
if (!is_readable($file)) {
throw new XmlValidatorException("Unbale to read input file: " . $file . "!");
}
}
}
$this->hash = sha1_file($file);
$this->file = $file;
if ($this->cache_only) {
return true;
}
}
$this->document = new DOMDocument();
$this->document->load($file);
$this->file = $file;
} catch (Exception $e) {
throw $e;
}
}
示例9: tasks
/**
* @inheritdoc
*/
public function tasks()
{
return ['default' => ['.description' => 'Show map of subtasks', '.task' => ['class' => 'cookyii\\build\\tasks\\MapTask', 'task' => $this]], 'update' => ['.description' => 'Self update `cookyii/build` package', '.task' => ['class' => '\\cookyii\\build\\tasks\\CallableTask', 'handler' => function () {
$source_url = 'http://cookyii.com/b/build.phar';
$checksum_url = 'http://cookyii.com/b/checksum';
$build_phar = $this->cwd . '/build.phar';
try {
$checksum = file_get_contents($checksum_url);
if ($checksum !== sha1_file($build_phar)) {
$result = copy($source_url, $build_phar);
if ($result) {
$this->log('<task-result> COPY </task-result> `build.phar` updated to actual version.');
} else {
$this->log('<task-error> ERR </task-error> Error updating `build.phar`');
}
} else {
$result = true;
if ($this->output->isVerbose()) {
$this->log('<task-result> OK </task-result> `build.phar` already updated.');
}
}
} catch (\Exception $e) {
if ($this->output->isVerbose()) {
$this->log('<task-error> ERR </task-error> Error updating `build.phar`');
}
throw $e;
}
return $result;
}]]];
}
示例10: setUp
public function setUp()
{
$this->image = realpath(APPLICATION_PATH . '/../' . self::PICTURE_LANDSCAPE);
$this->hash = sha1_file($this->image);
$this->adapter = $this->getMock('Zend_Cloud_StorageService_Adapter');
$this->service = new StorageService($this->adapter);
}
示例11: download
/**
* Download the remote Phar file.
*
* @param Updater $updater
*
* @throws \Exception on failure
*/
public function download(Updater $updater)
{
$version = $this->getCurrentRemoteVersion($updater);
if ($version === false) {
throw new \Exception('No remote versions found');
}
$versionInfo = $this->getAvailableVersions();
if (!isset($versionInfo[$version]['url'])) {
throw new \Exception(sprintf('Failed to find download URL for version %s', $version));
}
if (!isset($versionInfo[$version]['sha1'])) {
throw new \Exception(sprintf('Failed to find download checksum for version %s', $version));
}
$downloadResult = file_get_contents($versionInfo[$version]['url']);
if ($downloadResult === false) {
throw new HttpRequestException(sprintf('Request to URL failed: %s', $versionInfo[$version]['url']));
}
$saveResult = file_put_contents($updater->getTempPharFile(), $downloadResult);
if ($saveResult === false) {
throw new \Exception(sprintf('Failed to write file: %s', $updater->getTempPharFile()));
}
$tmpSha = sha1_file($updater->getTempPharFile());
if ($tmpSha !== $versionInfo[$version]['sha1']) {
unlink($updater->getTempPharFile());
throw new \Exception(sprintf('The downloaded file does not have the expected SHA-1 hash: %s', $versionInfo[$version]['sha1']));
}
}
示例12: resetsha1
function resetsha1()
{
$list = F('resetshalist');
if (empty($list)) {
$list = M('Picture')->field('id,path')->select();
F('resetshalist', $list);
F('resetshalistnum', count($list));
}
$total = F('resetshalistnum');
$i = 1;
foreach ($list as $key => $val) {
$i++;
$sha1 = sha1_file('.' . $val['path']);
M('Picture')->where("id={$val['id']}")->save(array('sha1' => $sha1));
unset($list[$key]);
if ($i > 1000 || empty($list)) {
$num = count($list);
if ($num > 0) {
F('resetshalist', $list);
$this->error('已经处理' . ($total - $num) . ',还有' . $num . '张');
} else {
F('resetshalist', null);
F('resetshalistnum', null);
$this->success('SHA1重置成功,总共有' . $total . '张图片');
}
break;
}
}
}
示例13: execute
/**
* {@inheritdoc}
*/
public function execute(ConsumerEvent $event, $directory)
{
$sha1LockFile = sha1_file($this->workingTempPath . '/' . $directory . '/composer.lock');
$this->triggerSuccess($event, array('link' => '/assets/' . $sha1LockFile . '/vendor.zip'));
$this->filesystem->remove($this->workingTempPath . '/' . $directory);
return 0;
}
示例14: calculate_hash
function calculate_hash($string, $hash = 'MD5', $isFile = false)
{
$str = '';
if ($isFile) {
switch ($hash) {
case 'SHA1':
$str = sha1_file($string);
break;
case 'MD5':
default:
$str = md5_file($string);
break;
}
} else {
switch ($hash) {
case 'SHA1':
$str = sha1($string);
break;
case 'MD5':
default:
$str = md5($string);
break;
}
}
return $str;
}
示例15: dl_apk
function dl_apk($id)
{
$config = array("a" => "credentials_us.conf", "b" => "credentials_us_f1.conf", "3" => "credentials_us_f2.conf", "4" => "credentials_us_f3.conf", "5" => "credentials_us_f4.conf", "6" => "credentials_us_f5.conf");
$cfg = array_rand($config, 1);
//$dl_cmd="python /home/wwwroot/www.voteapps.com/terry/gplay-cli/gplay-cli.py -d $id -f apkfiles -y -p -c credentials_us.conf";
$dl_cmd = "python /home/wwwroot/www.voteapps.com/terry/gplay-cli/gplay-cli.py -d {$id} -f /home/wwwroot/www.voteapps.com/apkfiles -y -p -c {$config[$cfg]}";
//echo $dl_cmd;
//$dl_480="youtube-dl -f $f -o $path_480 https://www.youtube.com/watch?v=$dl_url";
//执行下载
exec($dl_cmd, $output, $return_var);
//print_r($output);
//print_r($return_var);
//返回状态码 0 成功 1失败
$array[code] = $return_var;
if ($return_var == '0') {
$time = time();
$name = $id . $time . "[www.apkdigg.co]";
if (!file_exists("/home/wwwroot/www.voteapps.com/apkfiles/{$id}.apk")) {
$array[code] = '1';
} else {
rename("/home/wwwroot/www.voteapps.com/apkfiles/{$id}.apk", "/home/wwwroot/www.voteapps.com/apkfiles/{$name}.apk");
$array[file] = "apkfiles/{$name}.apk";
$array[sha] = sha1_file("/home/wwwroot/www.voteapps.com/apkfiles/{$name}.apk");
$pack_url = "/home/wwwroot/www.voteapps.com/apkfiles/{$name}.apk";
//$array[pack_info]= drupal_http_request($pack_url)->data;
//$array[pack_info]= curldom($pack_url);
$array['filemd5'] = md5_file($pack_url);
$array[pack_info] = apkinfo($pack_url);
// $array[pack_info]=get_permissions($pack_url);
}
} else {
}
return $array;
}