How to show file upload names and size? |
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.
IF you can provide a detailed error description, it will help to analyse it better.
-Abhijeet
06-15-2016, 05:58 AM
(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
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?
<?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 (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 ( )
Read this:
PHP NET $_FILES[] What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
On the place of "userfile", Please use name you used in your file input in form.
|
Welcome Guest, Not a member yet? Register Sign In |