为什么在XAMPP Linux上使用mkdir和PHP时会出现Permission Denied错误

I'm using XAMPP on my CentOS server. I just wrote a simple file upload script with PHP but there is a problem using mkdir() function, because of the error below:

Warning: mkdir(): Permission denied in /opt/lampp/htdocs/script.php on line 10

Also I can not use move_uploaded_file, because of the same problem.

How can I fix this issue?

You need to give permission to your web server or www folder like this, here www-data is apache group and user, make sure you have one apache user and group.

chown -R www-data:www-data /path/to/webserver/www

chmod -R g+rw /path/to/webserver/www

In your case

chmod -R g+rw /opt/lampp/htdocs