PHP在帖子后阅读上传的文件(PHP reading uploaded file after post)

编程入门 行业动态 更新时间:2024-10-22 08:40:28
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的任何文件,我该怎么做才能解决这个问题。

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

PHP reading uploaded file content issue

I upload a txt file, and I did the following

print_r($_FILES);

The output was

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

When I did the following

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

The $tmp_file_path return me /tmp/phpbyrYwN but $file_content return nothing, I went to root via ssh and check /tmp but did not see any file by the name /tmp/phpbyrYwN , what should I do to resolve this.

Should I state a default directory for uploaded file in any part of the code or ?

最满意答案

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

并尝试读取较低的文件名。

尝试没有strtolower :

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

your file system seem to be case-sensitive,

and you try to read the lower-cased file name.

try it without the strtolower:

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

更多推荐

本文发布于:2023-08-04 05:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上传   文件   帖子   PHP   post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!