PHP读取上传的文件后张贴


PHP reading uploaded file after post

PHP读取上传文件内容问题

我上传了一个txt文件,并进行了以下

print_r($_FILES);

输出为

Array ( [up_file] => Array ( [name] => upload.txt [type] => text/plain [tmp_name] => /tmp/phpbyrYwN [error] => 0 [size] => 26 ) ) 

当我做以下时

$tmp_file_path = strtolower($_FILES['up_file']['tmp_name']); //rename file
$file_content = file_get_contents($tmp_file_path);

$tmp_file_path返回me/tmp/phpbyrYwN但是$file_content什么也不返回,我通过ssh转到root并检查/tmp,但没有看到任何名为/tmp/phpbyrYwN的文件,我应该怎么解决这个问题。

我应该在代码的任何部分为上传的文件声明一个默认目录吗?

您的文件系统似乎区分大小写,

然后尝试读取小写的文件名。

尝试不使用strtolower:

<?php
$tmp_file_path = $_FILES['up_file']['tmp_name']; 
$file_content = file_get_contents($tmp_file_path);