【问题标题】:Why are my POSTed files not getting to server?为什么我发布的文件没有到达服务器?
【发布时间】:2019-05-16 17:25:10
【问题描述】:

发送 POST 方法文件到服务器没有文件。似乎有些人躲避我需要一个脚本来“解析”文件,但是据我了解 POST,文件应该 POST 并被复制到 apache 服务器,即使我什么都不做,对吗?

我已经尝试了许多修改.htaccess、php.ini 和apache2.conf 的解决方案。

目前我有

Apache2.conf

<Directory /var/www/>
  <IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME}.php -f
   RewriteRule (.*) $1.php [L]
   RewriteCond %{REQUEST_FILENAME}.xml -f
   RewriteRule (.*) $1.xml [L]
  </IfModule>

 Options FollowSymLinks
 AllowOverride All
 Require all granted
</Directory>

.htaccess

DirectorySlash Off

php.ini(upload_tmp_dir 不确定是否放置完整路径或来自 web 根目录。我也已阅读将其放在引号中)

file_uploads = On
upload_tmp_dir = /var/www/html/eSCL/ScanJobs 

Web 根目录是 /var/www/html 我想上传到 /var/www/html/eSCL/ScanJobs 扫描作业文件夹的权限为 777 所有者 www-data(适用于 ubuntu)

2 个帖子的错误是 404,一个是用于测试的 CURL,另一个是用于扫描的 Mopria Android 应用程序。

卷曲

curl -v -X POST -d @scansettings.xml  
http://localhost:80/eSCL/ScanJobs
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> POST /eSCL/ScanJobs HTTP/1.1
> Host: localhost
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Length: 605
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 605 out of 605 bytes
< HTTP/1.1 404 Not Found
< Date: Thu, 16 May 2019 17:14:32 GMT
< Server: Apache/2.4.18 (Ubuntu)
< Content-Length: 286
< Content-Type: text/html; charset=iso-8859-1
< 
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /eSCL/ScanJobs was not found on this server. 
</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at localhost Port 80</address>
</body></html>
* Connection #0 to host localhost left intact

上述 CURL 请求的 Apache 日志条目

127.0.0.1 - - [16/May/2019:12:14:32 -0500] "POST /eSCL/ScanJobs HTTP/1.1" 404 447 "-" "curl/7.47.0"

在使用 Mopria 的 Apache 日志中(包括成功命中)

192.168.0.8 - - [16/May/2019:12:17:59 -0500] "GET /eSCL/ScannerStatus HTTP/1.1" 200 716 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:04 -0500] "GET /eSCL/ScannerStatus HTTP/1.1" 200 715 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:09 -0500] "GET /eSCL/ScannerStatus HTTP/1.1" 200 715 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:13 -0500] "GET /eSCL/ScannerCapabilities HTTP/1.1" 200 1389 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:13 -0500] "GET /eSCL/ScannerStatus HTTP/1.1" 200 715 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:16 -0500] "GET /eSCL/ScannerStatus HTTP/1.1" 200 716 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:20 -0500] "GET /eSCL/ScannerCapabilities HTTP/1.1" 200 1389 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:20 -0500] "GET /eSCL/ScannerStatus HTTP/1.1" 200 715 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:25 -0500] "POST /eSCL/ScanJobs HTTP/1.1" 404 506 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:25 -0500] "GET /eSCL/ScannerStatus HTTP/1.1" 200 715 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:30 -0500] "GET /eSCL/ScannerStatus HTTP/1.1" 200 715 "-" "okhttp/3.9.1"
192.168.0.8 - - [16/May/2019:12:18:35 -0500] "GET /eSCL/ScannerStatus HTTP/1.1" 200 715 "-" "okhttp/3.9.1"

【问题讨论】:

    标签: post apache2


    【解决方案1】:

    您的文档根目录是 /var/www/,但我认为它应该是 /var/www/html。

    此外,要测试的 curl 请求是

    curl -v -F "file=@img.jpg" http://localhost/index.php

    当然上传的文件是临时放的

    /var/www/html/eSCL/ScanJobs/

    所以你必须用它来移动它

    move_uploaded_file($file_tmp,"eSCL/".$file_name);

    或任何你想要的文件夹。

    检查下面我的配置,来自 curl 的 200 响应代码和 print_r($_FILES),您可以在其中看到上传文件的临时路径。

    <Directory /var/www/html/>
      <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteCond %{REQUEST_FILENAME}.php -f
       RewriteRule (.*) $1.php [L]
       RewriteCond %{REQUEST_FILENAME}.xml -f
       RewriteRule (.*) $1.xml [L]
      </IfModule>
    
     Options FollowSymLinks
     AllowOverride All
     Require all granted
    </Directory>
    
    curl -v -F "file=@img.jpg" http://localhost/index.php
    *   Trying 127.0.0.1...
    * TCP_NODELAY set
    * Connected to localhost (127.0.0.1) port 80 (#0)
    > POST /index.php HTTP/1.1
    > Host: localhost
    > User-Agent: curl/7.58.0
    > Accept: */*
    > Content-Length: 1238948
    > Content-Type: multipart/form-data; boundary=------------------------98473343d22dab8a
    > Expect: 100-continue
    > 
    < HTTP/1.1 100 Continue
    < HTTP/1.1 200 OK
    < Date: Thu, 16 May 2019 21:29:01 GMT
    < Server: Apache/2.4.29 (Ubuntu)
    < Vary: Accept-Encoding
    < Content-Length: 282
    < Content-Type: text/html; charset=UTF-8
    < 
    Array
    (
        [file] => Array
            (
                [name] => img.jpg
                [type] => image/jpeg
                [tmp_name] => /var/www/html/eSCL/ScanJobs/phpZBF3Cc
                [error] => 0
                [size] => 1238763
            )
    
    )
    test
    * Connection #0 to host localhost left intact
    

    【讨论】:

    • 我现在不关心移动文件,只关心接收它。
    • 有一个虚拟主机 000-default.conf 应用于 /var/www 也适用于所有虚拟主机。这是 Ubuntu 上的默认安装。抱歉没有
    • 我不知道您安装了哪个 Ubuntu 版本,但 18.04 的默认值是 /var/www/html 但如果它是配置良好的 apache 配置,这并不重要。还有一件事可能是错误的,那就是您在 php.ini 中声明的变量 upload_tmp_dir =。检查它是否正确设置并在正确的 php.ini 中( /etc/php/7.2/apache2/php.ini 在我的例子中)如果你 phpinfo() 你会看到变量是否被初始化为声明的路径。
    • 是的,我的上传路径是类似的路径,除了 7.0 而不是 7.2 ,它正确显示在 phpinfo 中
    猜你喜欢
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-15
    • 2019-09-18
    • 1970-01-01
    • 2018-11-25
    • 2021-04-28
    相关资源
    最近更新 更多