0

i cannot seem to get php to process uploaded files at all. my current code looks like this:

<?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>

my php.ini file:

;;;;;;;;;;;;;;;;
; 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

and upon uploading litterally anything i get:

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

it is most likely glaringly obvious, but for the life of me i cant find what i am doing wrong.

kaioker2
  • 297
  • 3
  • 11

1 Answers1

0

You need to specify an action (php file) to process your form submission, and more specifically save the file.

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

Also, be sure to check permissions on the desired upload directory on your web server. On a LAMP environment, the apache user and www-data group should own the folder and have write permission to it.

Anson W Han
  • 409
  • 2
  • 7
  • PS- the errors you are encountering are attempts to pull file object information upon loading the web page before having uploaded any files. If you want to use the same php file to render the Webform and process it, add a conditional to only print the file info if the $_FILES is set – Anson W Han Nov 05 '17 at 05:32
  • leaving the action field blank sends the post data to the current page, so the page with the form should process the information, assuming the post data exists. i expect the error upon initial load of the page, its after i select a file and click submit that has baffled me as i still get the errors where i would assume they should clear as when the page reloads the post data should be available to it – kaioker2 Nov 05 '17 at 05:40