欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

What is the difference between sys_temp_dir and upload_tmp_dir in PHP?

Or rather, is there anyway to set the system temp directory (NOT the upload temp directory) in PHP?

When I run

echo sys_get_temp_dir();

I get /tmp. When I run

ini_get('upload_tmp_dir');

I get the directory that I specified in my php.ini file. Is there anyway to change what PHP uses for the sys temp dir?

I keep having random files show up in my /tmp directory. These are prefixed by "php" and then have a series of random numbers and letters. From what I can tell, these are probably being generated by PHP tmpfile or tempnam. httpd is the process that is using them when they are created. They are massive files that fill up my entire /tmp partition and take my server down. I can't figure out where they are coming from. I could increase the /tmp partition size from 500MB to 2GB but I'd rather avoid that if I can.

I don't understand where the sys_get_temp_dir() is pulling /tmp from. Everything I search for just tells me to change the upload_tmp_dir in .ini but these are two separate things.

in php.ini you should have to diferent settings for this:

; sys_temp_dir = "/tmp"
; upload_tmp_dir =

来自  https://stackoverflow.com/questions/30109695/what-is-the-difference-between-sys-temp-dir-and-upload-tmp-dir-in-php



php.ini中的upload_tmp_dir 参数

2018.07.23 01:00 241浏览


  • php.ini 中的 upload_tmp_dir 参数


php.ini 中的 upload_tmp_dir 的这个参数为上传文件的临时目录,需要 php 进程有读写权限。如何设置呢?


1. 查看 php 进程调用的 php.ini,一般调用 php 内置函数 phpinfo() 函数查看,方法很多:

找到 Loaded Configuration File:

Configuration File (php.ini) Path/usr/local/php/etc
Loaded Configuration File/usr/local/php/etc/php.ini

2. 用文本编辑器打开 /usr/local/php/etc/php.ini 找到以下位置:

upload_tmp_dir = /data/wwwroot/tmp


3. 检查 /data/wwwroot/tmp 是否可读写。

Linux 下,可以简单的设置 chmod 0777 /data/wwwroot/tmp

Windows 下,在目录上点击右键,设置安全 > 目录权限,加入 everyone 可读写。

4. 如果 php.ini 没有设置 upload_tmp_dir,那么默认 php 进程会读写系统的临时目录(Windows 默认为 C:/windows/temp,Linux 为 /tmp),所以为了保险起见还是设置下这个值。

来自  https://www.imooc.com/article/46293?block_id=tuijian_wz

普通分类: