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>'; Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.