php没有上传文件

时间:2017-11-05 04:15:39

标签: php upload

我似乎无法使用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

在上传任何我得到的内容时:

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()

它很可能是显而易见的,但对于我的生活,我无法找到我做错的事。

1 个答案:

答案 0 :(得分:0)

您需要指定一个操作(php文件)来处理表单提交,更具体地说是保存文件。

See examples and documentation at http://php.net/manual/en/features.file-upload.post-method.php

此外,请务必检查Web服务器上所需上载目录的权限。在LAMP环境中,apache用户和www-data组应该拥有该文件夹并具有写入权限。