post - 为什么我发布的文件没有到达服务器?
问题描述
将 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 Owner 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"
解决方案
您的文档根目录是/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
推荐阅读
- ios - Xamarin.Forms:iOS 相机不工作,图库工作正常(Android,两者都工作)
- javascript - 如何在同一个按钮上使用 onClick 调用这两个函数?
- c# - 编辑 DataGridTextColumn 或 DataGridComboBoxColumn 时自动完成
- python - 为什么视图路径 /slug:slug/slug:url/ 找不到 django
- symfony - Symfony 5 Phpunit 未定义方法
- python - 为什么大多数方法都是无效的,为什么将它们分配给变量有助于打印不是“无”值?
- node.js - 如何在 EJS 中使用模板字符串
- javascript - webpack splitchunksplugin minsize 不起作用
- reactjs - 如何使用 createContext 和 useReducer 管理多个 reducer
- ios - 如何将图像添加到存储在变量中的 QuickLook