读取不同目录中的文件php [英] Reading a file in a different directory php

查看:176
本文介绍了读取不同目录中的文件php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从一个低于脚本的文件夹中读取一个文件。当文件位于同一个目录下时,代码工作正常,但是当文件位于同一目录下时,每次都失败。
这里是我的代码

I am trying to read a file from a directory 2 folders lower than the script. The code works fine when the file is in the same directory but when its lower, it fails every time. Here's My code

<?php
$logfile = '/pass/uploads/test.aes';
$my_file = file_get_contents("$logfile");
echo $my_file;
?>

想法?

Ideas?

推荐答案

如果它是一个相对于当前目录的名称,则删除开始的斜杠。或者,将 __ DIR __ 添加到名称的开头,如 __ DIR__。 '/pass/uploads/test.aes'

Remove the beginning slash if it's meant to be a name relative to the current directory. Or, tack __DIR__ onto the beginning of the name, like __DIR__ . '/pass/uploads/test.aes'.

这篇关于读取不同目录中的文件php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆