I've made something like that for my vhosts on my local machine. Note that everything is defined in my vhost because you can't change upload_tmp_dir
and sys_temp_dir
in runtime.
<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>
How to confirm that everything works:
Create simple file:
$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 script: create file named 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>
.htaccess
will only work if PHP is enabled as an Apache module. Are.htaccess
overrides enabled in the server config? Have you tried.user.ini
? Have you tried just setting the value in your PHP script?tmp/
dir? stackoverflow.com/questions/2900690/…