我在 Ubuntu 18.04 上的 Apache Web 服务器上托管了多个域,但我无法为 PHP 设置 tmp 上传目录。
我尝试将其放入其中一个域的 .htaccess 中,但是在我测试时没有存储任何内容。
php_value upload_tmp_dir/var/www/example.com/tmp/
我对/var/www/example.com/tmp/文件夹的权限设置为 Chmod 775
是否有一种有效的方法可以在 .htaccess 或域的 .conf 文件中进行设置?
最佳答案
我在我的本地机器上为我的虚拟主机制作了类似的东西。请注意,所有内容都在我的虚拟主机中定义,因为您无法在运行时更改 upload_tmp_dir
和 sys_temp_dir
。
<VirtualHost *:80>
ServerName example.local
ServerAlias www.example.local
UseCanonicalName On
<Directory /mnt/storage/Server/example>
DirectoryIndex index.php
#Options +Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
php_admin_value upload_tmp_dir /mnt/storage/Server/example/temp/
php_admin_value sys_temp_dir /mnt/storage/Server/example/temp/
DocumentRoot "/mnt/storage/Server/example"
ErrorLog ${APACHE_LOG_DIR}/example.error.log
CustomLog ${APACHE_LOG_DIR}/example.access.log combined
</VirtualHost>
如何确认一切正常:
创建简单文件:
$dir = sys_get_temp_dir();
$file = tempnam($dir, rand());
var_dump(get_current_user());
var_dump($dir);
var_dump('is_writable: ' . (int)is_writable($dir));
var_dump('is_readable: ' . (int)is_readable($dir));
var_dump($file);
上传脚本:创建名为 upload.php 的文件
<?php
if (isset($_POST['submit'])) {
var_dump($_FILES);
}
?>
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="upload" id="upload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
关于多个域的PHP临时上传目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65471147/