I'm trying to reference the $_FILES inside a function I've created like the following... (shoterned) function item_picture_upload($file, $itemid, $alt) { if($file) { $filename = $_FILES['$file']['name']; echo $filename; } } PHP: And I call it like this... $retval = item_picture_upload($_FILE['file1'], 50, "the picture alt"); PHP: I'm trying to reference it but not working I'm trying to upload the file, rename and store permantly. The syntax must be wrong I think. Any input please?
$_FILES is not the same as $_FILE. That little squiggly thing at the end is a letter "S", not a worm that happened to crawn on your monitor.
Here you are passing $_FILES['file1'] which is an array: $retval = item_picture_upload($_FILE['file1'], 50, "the picture alt"); Code (markup): And then here you are treating it like a string: $filename = $_FILES['$file']['name']; Code (markup): Except that '$file' (name of string inside single quotes) doesn't do anything useful at all. How about this: $retval = item_picture_upload($_FILES['file1'], 50, "the picture alt"); Code (markup): function item_picture_upload($file, $itemid, $alt) { if(is_array($file) && count($file)) { $filename = $file['name']; echo $filename; } } Code (markup):
You need to set this ($_FILES['$file']['name'] outside of the function and pass it in as another variable also.