为什么我的POST文件无法到达服务器?

时间:2019-05-16 17:25:11

标签: post apache2

发送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不确定是否提供完整路径或来自网络根目录。我也读过将其用引号引起来)

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

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"

在Apache日志中使用Mopria(包括成功点击)

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"

1 个答案:

答案 0 :(得分:0)

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

此外,要测试的卷曲请求是

  

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