Welcome Guest, Not a member yet? Register   Sign In
How to show file upload names and size?
#1

I have webapp designed in php CodeIgniter MVC.

My view has the following code

              <button class="select_file">Upload documents (upto 5MB)</button>
              <input class="uploadFiles" id="uploadFiles" type="file" name="userfile[]" multiple />


I would like to show the file names and file sizes. What code do I need to write to show the same?

I had tried writing the code to display size as
<?php
                    if(count($_FILES['userfile']['name'])) {
                        foreach ($_FILES['userfile']['name'] as $file) {
                                //do your upload stuff here
                                echo $file;
            
                        }
                    }
  ?>

But the same is giving an error on page load itself. Kindly suggest.
Reply
#2

IF you can provide a detailed error description, it will help to analyse it better.

  Dodgy -Abhijeet
Reply
#3

(This post was last modified: 06-15-2016, 06:00 AM by Aneri. Edit Reason: Made a line BOLD as that is the main error )

A PHP ERROR WAS ENCOUNTERED

Severity: Notice
Message: Undefined index: userfile
Filename: content/content_create_case_details.php
Line Number: 83
Backtrace:
File: /var/www/application/views/service/content/content_create_case_details.php
Line: 83
Function: _error_handler
File: /var/www/application/controllers/Service.php
Line: 149
Function: view
File: /var/www/index.php
Line: 292
Function: require_once
Reply
#4

I think I understand the problem the userfile is an input type which will only become relevant when the form is submitted.

So is there a way that I can read the input type before the form submitted?
Reply
#5

<?php
$files = array();
$count_files = count($_FILES["userfile"]["name"]);
if($count_files!=0){
for($i=0;$i < $count_files;$i++){
$files[$i]["name"] = $_FILES["userfile"]["name"][$i];
$files[$i]["type"] = $_FILES["userfile"]["type"][$i];
$files[$i]["tmp_name"] = $_FILES["userfile"]["tmp_name"][$i];
$files[$i]["error"] = $_FILES["userfile"]["error"][$i];
$files[$i]["size"] = $_FILES["userfile"]["size"][$i];
}
}

print_r($files);
?>



Use this code in form submit page for get all files in single array
Reply
#6

(06-15-2016, 05:33 AM)abhijeetgk Wrote: IF you can provide a detailed error description, it will help to analyse it better.

@ mp.inviable

I tried your code it still gives me the same error plus the array line

A PHP ERROR WAS ENCOUNTERED
Severity: Notice
Message: Undefined index: userfile
Filename: content/content_create_case_details.php
Line Number: 94
Array ( )
Reply
#7

Read this:

PHP NET $_FILES[]
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

On the place of "userfile", Please use name you used in your file input in form.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB