解析配置文件以在php中提供绝对路径的替代方法是什么。
ie)我正在读取db配置文件,如:
$config = parse_ini_file('../../../config.ini');
我需要给出上面的绝对路径,如:
$_SERVER['DOCUMENT_ROOT'].'/<my_path>/config.ini';
我需要避免使用&#39; ../../'在我的路径
如果我使用:
$ config = $ _SERVER [&#39; DOCUMENT_ROOT&#39;]。&#39; /my_path/my_path/config.ini' ;;
我得到了
非法字符串偏移&#39;用户名&#39;
答案 0 :(得分:1)
在项目的Root文件夹中保留config.php
,您可以添加此类数据。接下来是许多PHP项目,包括WordPress。
例如来自WordPress
define('ABSPATH', dirname(__FILE__) . '/');
他们在ABSPATH
中定义了wp-config.php
,并且它拥有应用的绝对路径。所以你可以在你想要的任何地方引用它们,
在你的情况下,这可能就像是。
parse_ini_file(ABSPATH. 'config.ini');
答案 1 :(得分:0)
好的,我在下面使用它:
import tensorflow as tf
import sys
image_path = sys.argv[1]
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
#loads label file, strips off carriage return
label_lines = [line.strip() for line in tf.gfile.GFile("/tmp/output_labels.txt")]
# Unpersists graph from file
with tf.gfile.FastGFile("/tmp/output_graph.pb", 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
with tf.Session() as sess:
# Feed the image data as input to the graph an get first prediction
softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
predictions = sess.run(softmax_tensor, \
{'DecodeJpeg/contents:0':image_data})
# Sort to show labels of first prediction in order of confidence
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
for node_id in top_k:
human_string = label_lines[node_id]
score = predictions[0][node_id]
print('%s (score = %.2f)' % (human_string, score))