我无法在Linux上使用PHP上传文件。

huangapple go评论82阅读模式
英文:

I can not upload a file using PHP on Linux

问题

I'm running PHP 8.2.9, Apache 2.4.37 (Red Hat Enterprise Linux) on RedHat 8.7.

Somehow, I'm not able to upload the file to a specific folder under my project.

This is the folder where the project is running /opt/policy_editor/www/html
drwxr-xr-x.  2 apache apache   62 Mar  2 14:51 deprecated_files
drwxr-xr-x.  2 apache apache 4096 Mar 13 15:39 img
drwxr-xr-x. 11 apache apache 4096 Aug  4 10:04 inc
-rw-r--r--.  1 apache apache 8646 Aug  4 09:49 index.php
-rw-r--r--.  1 apache apache   19 Mar  2 14:51 info.php
-rw-r--r--.  1 apache apache 5401 Jul 28 09:38 login.php
-rw-r--r--.  1 apache apache  101 Mar  2 14:51 logout.php
-rw-r--r--.  1 apache apache  395 Mar  2 14:51 mail.php
-rw-r--r--.  1 apache apache 1485 Mar 13 15:39 maintenance.php
drwxr-xr-x.  2 apache apache 4096 Jul 28 09:38 sql_updates
drwxrwxrwx.  2 apache apache    6 Aug  4 10:11 tmp
drwxrwxrwx.  2 apache apache    6 Aug  4 09:47 uploads

I have all the right permission in place, but still not able to move the file to uploads.
I have confirmed the upload file is saved on /tmp on system folder

But I get these errors

Warning: move_uploaded_file(uploads/test.pol): Failed to open stream: Permission denied in /opt/policy_editor/www/html/inc/admin/admin_post_commands.php on line 487

Warning: move_uploaded_file(): Unable to move "/tmp/phpV2j8Vv" to "uploads/test.pol" in /opt/policy_editor/www/html/inc/admin/admin_post_commands.php on line 487

I have seen similar errors on this channel; most solutions point to changing permissions.
Unless I'm missing something, permission seems to be not my case.
I also have tried to move the application under /var/www, but I get the same issue.

英文:

I´m running PHP 8.2.9, Apache 2.4.37 (Red Hat Enterprise Linux) on RedHat 8.7.

Somehow, I´m not able to upload the file to a specific folder under my project.

This this the folder where the project is running /opt/policy_editor/www/html
drwxr-xr-x.  2 apache apache   62 Mar  2 14:51 depreceated_files
drwxr-xr-x.  2 apache apache 4096 Mar 13 15:39 img
drwxr-xr-x. 11 apache apache 4096 Aug  4 10:04 inc
-rw-r--r--.  1 apache apache 8646 Aug  4 09:49 index.php
-rw-r--r--.  1 apache apache   19 Mar  2 14:51 info.php
-rw-r--r--.  1 apache apache 5401 Jul 28 09:38 login.php
-rw-r--r--.  1 apache apache  101 Mar  2 14:51 logout.php
-rw-r--r--.  1 apache apache  395 Mar  2 14:51 mail.php
-rw-r--r--.  1 apache apache 1485 Mar 13 15:39 maintenance.php
drwxr-xr-x.  2 apache apache 4096 Jul 28 09:38 sql_updates
drwxrwxrwx.  2 apache apache    6 Aug  4 10:11 tmp
drwxrwxrwx.  2 apache apache    6 Aug  4 09:47 uploads

I have all the right permission in place, but still not able to move the file to uploads.
I have confirmed the upload file is saved on /tmp on system folder

But I get these errors

Warning: move_uploaded_file(uploads/test.pol): Failed to open stream: Permission denied in /opt/policy_editor/www/html/inc/admin/admin_post_commands.php on line 487

Warning: move_uploaded_file(): Unable to move "/tmp/phpV2j8Vv" to "uploads/test.pol" in /opt/policy_editor/www/html/inc/admin/admin_post_commands.php on line 487

I have seem similar errors on this channel, most solution points to change permission.
Unless I´m missing something, permission seems to be not my case.
I also have tried to move the application under /var/www, but I get the same issue.

答案1

得分: 2

你似乎有关于相对和绝对文件路径的问题。

使用绝对路径测试并使用

__DIR__ . "folder/file.ext";
英文:

It seems you have an issue about Relative & Absolute file paths.

Test with absolute path and with

__DIR__ . "folder/file.ext";

huangapple
  • 本文由 发表于 2023年8月4日 23:05:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76837151.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定