我有一个简单的PHP表单,在localhost上有2个上传输入。当我将表单的enctype设置为multipart/form-data
时,它不会发送任何信息。我打印了$_FILES
和$_POST
,两者都是Array()
并且为空。
这是我在insert_tour.php
文件中的php代码:
$path = "upload/";
for ($i = 0; $i < count($_FILES['images']['name']); $i++) {
$image_name = $_FILES['images']['name'][$i];
$image_path = $path . basename($_FILES['images']['name'][$i]);
if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $image_path)) {
array_push($images, $image_path);
} else {
echo "There was an error uploading the images, please try again!";
}
}
$video_path = $path . basename($_FILES['tour_video']['name']);
if (move_uploaded_file($_FILES['tour_video']['tmp_name'], $video_path)) {
} else {
echo "There was an error uploading the video, please try again!";
}
// Process the post data and files and send to db here ...
这是我的表格代码:
<form action="tour_insert.php" method="post" enctype="multipart/form-data">
<!-- other inputs for form -->
<input name="tour_video" type="file">
<input name="images[]" type="file" multiple="multiple">
<input name="add_tour" type="submit" value="submit">
</form>
问题是它不会在$_POST
或$_FILES
中发送任何信息。
这就是打印$_SERVER
给我的东西:
Array ( [UNIQUE_ID] => WmCTwKwSjVEAABJMH-QAAAA- [HTTP_HOST] => localhost [HTTP_CONNECTION] => keep-alive [CONTENT_LENGTH] => 14532844 [HTTP_CACHE_CONTROL] => max-age=0 [HTTP_ORIGIN] => http://localhost [HTTP_UPGRADE_INSECURE_REQUESTS] => 1 [CONTENT_TYPE] => multipart/form-data; boundary=----WebKitFormBoundarydQZ9i0QtJC8p0A5e [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 [HTTP_REFERER] => http://localhost/dalahu/add_tour.php [HTTP_ACCEPT_ENCODING] => gzip, deflate, br [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.9,fa;q=0.8,ja;q=0.7 [HTTP_COOKIE] => PHPSESSID=s44btr20s2to36kn7tsk4rk717 [PATH] => C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\Amirition\AppData\Local\Programs\Python\Python36-32;C:\Users\Amirition\AppData\Local\Programs\Python\Python36-32\Scripts;D:\Python\ajax_lastsecond\chromedriver.exe;C:\Users\Amirition\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Bandizip\;C:\Program Files\Microsoft VS Code\bin [SystemRoot] => C:\Windows [COMSPEC] => C:\Windows\system32\cmd.exe [PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC [WINDIR] => C:\Windows [SERVER_SIGNATURE] => [SERVER_SOFTWARE] => Apache/2.2.27 (Win32) DAV/2 mod_ssl/2.2.27 OpenSSL/1.0.2e mod_fcgid/2.3.9 mod_wsgi/3.4 Python/2.7.6 PHP/7.0.0 mod_perl/2.0.8 Perl/v5.16.3 [SERVER_NAME] => localhost [SERVER_ADDR] => 127.0.0.1 [SERVER_PORT] => 80 [REMOTE_ADDR] => 127.0.0.1 [DOCUMENT_ROOT] => D:/MAMP/htdocs [SERVER_ADMIN] => testemail@test.com [SCRIPT_FILENAME] => D:/MAMP/htdocs/dalahu/tour_insert.php [REMOTE_PORT] => 3105 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => POST [QUERY_STRING] => [REQUEST_URI] => /dalahu/tour_insert.php [SCRIPT_NAME] => /dalahu/tour_insert.php [PHP_SELF] => /dalahu/tour_insert.php [REQUEST_TIME_FLOAT] => 1516278720.141 [REQUEST_TIME] => 1516278720 )
答案 0 :(得分:0)
通过增加post_max_size
文件中的php.ini
来解决此问题。默认值为8MB,可以增加此值。