我似乎无法得到PHP来处理上传的文件。 我目前的代码如下所示:
<?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> <html> <body> <form action="" method="POST" enctype="multipart/form-data"> <input type="file" name="image"> <input type="submit"> </form> <p>Sent file: <?php echo $_FILES['image']['name']; ?></p><br> <p>File size: <?php echo $_FILES['image']['size']; ?></p><br> <p>File type: <?php echo $_FILES['image']['type']; ?></p><br> <?php print_r($_FILES); ?> </body> </html>
我的php.ini文件:
;;;;;;;;;;;;;;;; ; File Uploads ; ;;;;;;;;;;;;;;;; ; Whether to allow HTTP file uploads. ; http://php.net/file-uploads file_uploads = On ; Temporary directory for HTTP uploaded files (will use system default if not ; specified). ; http://php.net/upload-tmp-dir ;upload_tmp_dir = ; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 10000M ; Maximum number of files that can be uploaded via a single request max_file_uploads = 20
并在litterally上载任何我得到:
Sent file: Notice: Undefined index: image in /var/www/upload.php on line 13 File size: Notice: Undefined index: image in /var/www/upload.php on line 14 File type: Notice: Undefined index: image in /var/www/upload.php on line 15 Array()
这很可能是显而易见的,但是对于我来说,我无法find自己做错了什么。
你需要指定一个动作(php文件)来处理你的表单提交,更具体的保存文件。
请参阅http://php.net/manual/en/features.file-upload.post-method.php上的示例和文档
此外,请务必在您的Web服务器上检查所需上载目录的权限。 在LAMP环境中,apache用户和www-data组应拥有该文件夹并具有写入权限。