提问人:Harsh Gupta 提问时间:10/10/2023 最后编辑:Harsh Gupta 更新时间:10/10/2023 访问量:81
没有这样的文件或目录
No such file or directory
问:
在代码中,我无法确定路径出了什么问题,因此在 Appwrite 中运行该函数会导致文件未找到问题
我参考了这段代码 https://github.com/appwrite/templates/blob/main/php/sync-with-algolia/src/utils.php
<?php
$staticFolder = dirname(__FILE__) . '/../static';
/**
* Returns the contents of a file in the static folder
* @param string $fileName
* @return string Contents of static/{$fileName}
*/
function get_static_file(string $fileName): string
{
global $staticFolder;
$file = $staticFolder . '/' . $fileName;
return file_get_contents($file);
}
/**
* Throws an exception if any of the keys are missing from the object
* @param array|object $obj
* @param string[] $keys
* @throws Exception
*/
function throw_if_missing(mixed $obj, array $keys): void
{
$missing = [];
foreach ($keys as $key) {
if (!isset($obj[$key]) || empty($obj[$key])) {
$missing[] = $key;
}
}
if (count($missing) > 0) {
throw new Exception('Missing required fields: ' . implode(', ', $missing));
}
}
/**
* Interpolates values into a template string.
* @param string $template The template string containing placeholders like "{{key}}".
* @param array<string, string|null> $values An associative array with keys and values to replace in the template.
* @return string The interpolated string with placeholders replaced by corresponding values.
*/
function interpolate(string $template, array $values): string
{
return preg_replace_callback('/{{([^}]+)}}/', function ($matches) use ($values) {
$key = $matches[1];
return isset($values[$key]) ? $values[$key] : '';
}, $template);
}
答: 暂无答案
评论