alemapo Posted August 19, 2009 Share Posted August 19, 2009 Hi, I am creating an external function to do upload and move of images on my web pages so that I can call the same function from multiple screens. I need to pass the $_FILES array to the function but can not figure out the syntax. I have tried everything I can think of and get syntax errors. My function name is upload_image and I need to pass the entire $_FILES array to the function so that all the error checking and actual move can be done in the function. I need help with the function declaration line with the array and the call to the function line for the array. I have tried everything I can think of. For the declaration I have tried: function upload_image takes_array($_FILES) { (or) function upload_image($_FILES) { For the call to the function I have tried: upload_image($_FILES['upload']['type']); (Or) upload_image($_FILES); No variation I try works. I know you can send an array to the function but do I need to do something different since this is $_FILES? Any help would be greatly appreciated. Thanks! Pamela Link to comment https://forums.phpfreaks.com/topic/170949-solved-pass-_files-array-to-function/ Share on other sites More sharing options...
Garethp Posted August 19, 2009 Share Posted August 19, 2009 foreach($_FILES as $k=>$v) { $C[$k]=$v; } dosomethingwithit($C); Also, don't declare function Something($_FILES) because $_FILES is reserved, try function Something($TempData) Link to comment https://forums.phpfreaks.com/topic/170949-solved-pass-_files-array-to-function/#findComment-901610 Share on other sites More sharing options...
trq Posted August 19, 2009 Share Posted August 19, 2009 $_FILES is a global array and won't need to be passed to your function at all. Link to comment https://forums.phpfreaks.com/topic/170949-solved-pass-_files-array-to-function/#findComment-901623 Share on other sites More sharing options...
alemapo Posted August 19, 2009 Author Share Posted August 19, 2009 Thanks thorpe! Link to comment https://forums.phpfreaks.com/topic/170949-solved-pass-_files-array-to-function/#findComment-901638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.