dennismonsewicz Posted October 30, 2008 Share Posted October 30, 2008 I have the following error from my code: Warning: Invalid argument supplied for foreach() in csv_upload.php on line 10 Here is my code: foreach($_FILES['file']['name'] as $n => $name) { if(!empty($name)) { $target_path = "path_to_upload_folder/" . $name; if(move_uploaded_file($_FILES['file']['tmp_name'][$n], $target_path)) { echo 'files loaded'; } } } form code: echo '<form action="csv_upload.php?action=upload&osCAdminID=' . $session_id . '" method="post">'; echo '<label for="file1">File 1</label> <input type="file" name="file[]" />'; echo '<br /><br />'; echo '<label for="file2">File 2</label> <input type="file" name="file[]" />'; echo '<br /><br />'; echo '<input type="submit" value="Submit Information" />'; echo '</form>'; Link to comment https://forums.phpfreaks.com/topic/130763-solved-foreach-help/ Share on other sites More sharing options...
Mchl Posted October 30, 2008 Share Posted October 30, 2008 This error occurs when the variable passed to foreach() is not an array, or the array is empty. In other words, check if $_FILES['file']['name'] is an array and if it has at least one element. Link to comment https://forums.phpfreaks.com/topic/130763-solved-foreach-help/#findComment-678638 Share on other sites More sharing options...
sasa Posted October 30, 2008 Share Posted October 30, 2008 add enctype="multipart/form-data" in form tag Link to comment https://forums.phpfreaks.com/topic/130763-solved-foreach-help/#findComment-678640 Share on other sites More sharing options...
dennismonsewicz Posted October 30, 2008 Author Share Posted October 30, 2008 thanks sasa! Its been a really long week... getting laid off from your job is a week killer! Link to comment https://forums.phpfreaks.com/topic/130763-solved-foreach-help/#findComment-678657 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.