How to show file upload names and size? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How to show file upload names and size? (/showthread.php?tid=65467) |
How to show file upload names and size? - Aneri - 06-15-2016 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. RE: How to show file upload names and size? - abhijeetgk - 06-15-2016 IF you can provide a detailed error description, it will help to analyse it better. RE: How to show file upload names and size? - Aneri - 06-15-2016 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 RE: How to show file upload names and size? - Aneri - 06-15-2016 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? RE: How to show file upload names and size? - mp.inviable - 06-15-2016 <?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 RE: How to show file upload names and size? - Aneri - 06-15-2016 (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 ( ) RE: How to show file upload names and size? - InsiteFX - 06-15-2016 Read this: PHP NET $_FILES[] RE: How to show file upload names and size? - mp.inviable - 06-20-2016 On the place of "userfile", Please use name you used in your file input in form. |